local extension = Package:new("YS__inazima")
extension.extensionName = "genshin"

local U = require "packages/utility/utility"


Fk:loadTranslationTable{
     ["YS__inazima"] = "○神-稻妻",
     ["YS"] = "○神",
}

--- 整肃记录技能
local mobile_zhengsu_recorder = fk.CreateTriggerSkill{
  name = "mobile_zhengsu_recorder",

  refresh_events = {fk.CardUsing, fk.AfterCardsMove, fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    if player.dead then return end
    local mark1, mark2, mark3 = "@zhengsu_bianzhen-turn", "@zhengsu_leijin-turn", "@zhengsu_mingzhi-turn"
    local check_play = player.phase == Player.Play and
    ((player:getMark(mark1) == "" or type(player:getMark(mark1)) == "table")
    or (player:getMark(mark2) == "" or type(player:getMark(mark2)) == "table"))
    local check_discard = player.phase == Player.Discard and
    (player:getMark(mark3) == "" or type(player:getMark(mark3)) == "table")
    if event == fk.CardUsing then
      return target == player and check_play
    elseif event == fk.AfterCardsMove then
      return check_discard
    else
      return target == player and (check_play or check_discard)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local broadcastFailure = function (p, choice)
      room:setPlayerMark(p, "@"..choice.."-turn", "zhengsu_failure")
      for _, v in ipairs(p:getTableMark("zhengsu_skill-turn")) do
        if choice == v[3] then
          room:getPlayerById(v[1]):broadcastSkillInvoke(v[2], 3)
        end
      end
    end
    if event == fk.CardUsing then
      local mark = player:getMark("@zhengsu_leijin-turn")
      if (mark == "" or type(mark) == "table") and data.card.number > 0 then
        if mark == "" then
          mark = {}
        else
          mark = table.map(mark, function(v) return Card:strToNumber(v) end)
        end
        table.insert(mark, data.card.number)
        if #mark > 3 then table.remove(mark, 1) end
        if #mark > 1 and mark[#mark] <= mark[#mark-1] then
          broadcastFailure(player, "zhengsu_leijin")
        else
          mark = table.map(mark, function(v) return Card:getNumberStr(v) end)
          room:setPlayerMark(player, "@zhengsu_leijin-turn", mark)
        end
      end
      mark = player:getMark("@zhengsu_bianzhen-turn")
      if (mark == "" or type(mark) == "table") then
        local suit = data.card:getSuitString(true)
        if suit ~= "log_nosuit" then
          if mark == "" then mark = {} end
          if table.find(mark, function(v) return v ~= suit end) then
            broadcastFailure(player, "zhengsu_bianzhen")
            return
          elseif #mark < 2 then
            table.insert(mark, suit)
          end
          room:setPlayerMark(player, "@zhengsu_bianzhen-turn", mark)
        end
      end
    elseif event == fk.AfterCardsMove then
      local mark = player:getTableMark("@zhengsu_mingzhi-turn")
      for _, move in ipairs(data) do
        if move.from == player.id and move.skillName == "phase_discard" then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              local suit = Fk:getCardById(info.cardId):getSuitString(true)
              if not table.insertIfNeed(mark, suit) then
                broadcastFailure(player, "zhengsu_mingzhi")
                return
              end
            end
          end
        end
      end
      room:setPlayerMark(player, "@zhengsu_mingzhi-turn", mark)
    elseif event == fk.EventPhaseEnd then
      local mark1, mark2, mark3 = "@zhengsu_bianzhen-turn", "@zhengsu_leijin-turn", "@zhengsu_mingzhi-turn"
      if player.phase == Player.Play then
        if player:getMark(mark1) ~= 0 then
          if #player:getTableMark(mark1) >= 2 then
            room:setPlayerMark(player, mark1, "zhengsu_success")
          else
            broadcastFailure(player, "zhengsu_bianzhen")
          end
        end
        if player:getMark(mark2) ~= 0 then
          if #player:getTableMark(mark2) >= 3 then
            room:setPlayerMark(player, mark2, "zhengsu_success")
          else
            broadcastFailure(player, "zhengsu_leijin")
          end
        end
      else
        if #player:getTableMark(mark3) >= 2 then
          room:setPlayerMark(player, mark3, "zhengsu_success")
        else
          broadcastFailure(player, "zhengsu_mingzhi")
        end
      end
    end
  end,
}

---@param player ServerPlayer @ 发起整肃的玩家
---@param target ServerPlayer @ 执行整肃的玩家
---@param skillName string @ 技能名
---@param prompt string @ 提示信息
--- 发起整肃
local function startZhengsu(player, target, skillName, prompt)
  skillName = skillName or ""
  prompt = prompt or ""
  local room = player.room
  local choices = {"zhengsu_leijin", "zhengsu_bianzhen", "zhengsu_mingzhi"}
  local choice = room:askForChoice(player, choices, skillName, prompt, true)
  local mark_name = "@" .. choice .. "-turn"
  if target:getMark(mark_name) == 0 then
    room:setPlayerMark(target, mark_name, "")
  end
  room:addTableMark(target, "zhengsu_skill-turn", {player.id, skillName, choice})
  room.logic:addTriggerSkill(mobile_zhengsu_recorder)
end

---@param player ServerPlayer @ 发起整肃的玩家
---@param target ServerPlayer @ 执行整肃的玩家
---@param skillName string @ 技能名
--- 检查整肃成功
local function checkZhengsu(player, target, skillName)
  for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
    if v[2] == skillName and v[1] == player.id then
      return target:getMark("@" .. v[3].. "-turn") == "zhengsu_success"
    end
  end
  return false
end

local YS__sllh = General(extension, "YS__sllh", "Cryo", 3, 3, General.Female)
local YS__sllhwin = fk.CreateActiveSkill{ name = "YS__sllh_win_audio" }
YS__sllhwin.package = extension
Fk:addSkill(YS__sllhwin)
local YS__binghua = fk.CreateViewAsSkill{
  name = "YS__binghua",
  anim_type = "offensive",
  pattern = "ice__slash",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).trueName == "slash"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("ice__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local YS__binghuaSlash = fk.CreateTriggerSkill{
  name = "#YS__binghuaSlash",
  events = {fk.CardUseFinished},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
     return target == player and player:hasSkill(YS__binghua) and data.card.trueName == "slash"
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    if player:usedSkillTimes("ice_damage_skill", Player.HistoryPhase) > 0 then
      player.room:addPlayerMark(player, MarkEnum.SlashResidue.."-phase")
      player:setSkillUseHistory("ice_damage_skill", 0, Player.HistoryPhase)
      end
    end,
  priority = 2,
}
local YS__shuangmie = fk.CreateTriggerSkill{
  name = "YS__shuangmie",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if data.card.trueName ~= "jink" and data.card.trueName ~= "nullification" and data.tos ~= nil then
    local room = player.room
    local cardnum1 = player:getHandcardNum()
    local targets = TargetGroup:getRealTargets(data.tos)
    local to = player.room:getPlayerById(targets[1])
      if to then
      local cardnum2 = to:getHandcardNum()
      return  target == player and player:hasSkill(self.name) and cardnum1 == cardnum2 and to ~= player and player.phase == Player.Play
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = TargetGroup:getRealTargets(data.tos)
    local to = player.room:getPlayerById(targets[1])
      room:damage{
        from = player,
        to = to,
        damage = 1,
        damageType = fk.IceDamage,
        skillName = self.name,
      }
      end,
}
local YS__xiabu = fk.CreateTriggerSkill{
  name = "#YS__xiabu",
  anim_type = "drawcard",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getMark("YS__xiabu") ~= 0 then
      for _, move in ipairs(data) do
        if move.extra_data and move.extra_data.YS__xiabu then
          for _, id in ipairs(move.extra_data.YS__xiabu) do
            if player.room:getCardArea(id) == Card.DiscardPile then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    for _, move in ipairs(data) do
      if move.extra_data and move.extra_data.YS__xiabu then
        for _, id in ipairs(move.extra_data.YS__xiabu) do
          if room:getCardArea(id) == Card.DiscardPile then
            table.insertIfNeed(ids, id)
          end
        end
      end
    end
    local cards = room:askForCardsChosen(player, player, 1, #ids, {card_data = {{self.name, ids}}}, self.name)
    if #cards > 0 then
      local dummy = Fk:cloneCard("dilu")
      dummy:addSubcards(cards)
      local rand = math.random(4, 6)
      if rand == 4 then
        player:broadcastSkillInvoke("A_YS__xiabu", 4)
      elseif rand == 5 then
        player:broadcastSkillInvoke("A_YS__xiabu", 5)
      else
        player:broadcastSkillInvoke("A_YS__xiabu", 6)
      end
      room:obtainCard(player.id, dummy, true, fk.ReasonJustMove)
    end
  end,

  refresh_events = {fk.BeforeCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if (not move.from or move.from ~= player.id) and (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonJudge) and
          move.toArea == Card.DiscardPile then
          return true
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if (not move.from or move.from ~= player.id) and (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonJudge) and
        move.toArea == Card.DiscardPile then
        local ids = {}
        if player:getMark("YS__xiabu") ~= 0 then
        local suitsx = player:getMark("YS__xiabu")
        suitsx = suitsx:split("+")
        for _, info in ipairs(move.moveInfo) do
          if table.contains(suitsx, Fk:getCardById(info.cardId):getSuitString()) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
        if #ids > 0 then
          move.extra_data = move.extra_data or {}
          move.extra_data.YS__xiabu = ids
        end
      end
    end
  end,
}
local YS__xiabuView = fk.CreateTriggerSkill{
  name = "#YS__xiabuView",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player.phase == Player.Play and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local room =player.room
    local availableTargets = table.map(table.filter(room:getOtherPlayers(player), function(p)
      return player:inMyAttackRange(p) and not p:isKongcheng()
    end), Util.IdMapper)
    if #availableTargets == 0 then return false end
    local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "观看一名角色的手牌", "A_YS__xiabu", true)
    if #targets > 0 then
      player.room:doIndicate(player.id, targets)
      self.cost_data = targets[1]
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data)
    U.viewCards(player, to:getCardIds("h"))
  end,
}
local A_YS__xiabu = fk.CreateActiveSkill{
  name = "A_YS__xiabu",
  anim_type = "control",
  card_num = 1,
  target_num = 0,
  mute = true,
  can_use = function(self, player)
    return player.phase == Player.Play and player:hasSkill(self)
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    if Self:getMark("YS__xiabu") ~= 0 then
      local suitsx = Self:getMark("YS__xiabu")
      suitsx = suitsx:split("+")
     return not table.contains(suitsx, Fk:getCardById(to_select):getSuitString())
    else return true end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    local rand = math.random(1, 3)
      if rand == 1 then
        player:broadcastSkillInvoke("A_YS__xiabu", 1)
      elseif rand == 2 then
        player:broadcastSkillInvoke("A_YS__xiabu", 2)
      else
        player:broadcastSkillInvoke("A_YS__xiabu", 3)
      end
    local suit = Fk:getCardById(effect.cards[1]):getSuitString()
      if table.contains({ "spade", "heart", "club", "diamond" }, suit) then
        local m = player:getMark("YS__xiabu")
        if m == 0 then
          m = suit
        elseif type(m) == "string" then
          local suits = m:split("+")
          table.insertIfNeed(suits, suit)
          m = table.concat(suits, "+")
        end
        room:setPlayerMark(player, "YS__xiabu", m)
        local card_suits_table = {
          spade = "♠",
          club = "♣",
          heart = "♥",
          diamond = "♦",
        }
        room:setPlayerMark(player, "@YS__xiabu", table.concat(
          table.map(m:split("+"), function(s) return card_suits_table[s] end)
          , ""))
      end
  end,
}
local YS__xiabuReset = fk.CreateTriggerSkill{
  name = "#YS__xiabuReset",
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@YS__xiabu", 0)
    player.room:setPlayerMark(player, "YS__xiabu", 0)
  end,
}
YS__sllh:addSkill(YS__binghua)
A_YS__xiabu:addRelatedSkill(YS__xiabuView)
YS__binghua:addRelatedSkill(YS__binghuaSlash)
YS__sllh:addSkill(YS__shuangmie)
A_YS__xiabu:addRelatedSkill(YS__xiabu)
YS__sllh:addSkill(A_YS__xiabu)
A_YS__xiabu:addRelatedSkill(YS__xiabuReset)

Fk:loadTranslationTable{
  ["YS__sllh"] = "神里绫华",
  ["YS__binghua"] = "冰华",
  ["YS__shuangmie"] = "霜灭",
  ["A_YS__xiabu"] = "霞步",
  ["@YS__xiabu"] = "霞步",
  ["#YS__xiabu"] = "霞步",
  [":YS__binghua"] = "出牌阶段，你可以将一张【杀】当冰【杀】使用；当你使用冰【杀】弃置目标角色牌结算后，你令此【杀】不计入次数。",
  [":YS__shuangmie"] = "当你使用牌指定唯一目标结算后，若你与其手牌数相等，则你可以对其造成一点冰冻伤害",
  [":A_YS__xiabu"] = "出牌阶段每种花色限一次，你可以弃置一张牌；然后直到本回合结束，当有相同花色的牌因弃置进入弃牌堆时，你可以获得之。出牌阶段开始时，你可以观看你攻击范围内一名有手牌的其他角色的手牌。",
  ["$YS__binghua1"] = "起舞吧。",
  ["$YS__binghua2"] = "雪纷飞。",
  ["$YS__binghua3"] = "失礼了。",
  ["$YS__shuangmie1"] = "神里流…霜灭！",
  ["$YS__shuangmie2"] = "樱吹雪。",
  ["$YS__shuangmie3"] = "拿下了！",
  ["$A_YS__xiabu1"] = "烦请赐教。",
  ["$A_YS__xiabu2"] = "呵呵，请多关照。",
  ["$A_YS__xiabu3"] = "神里绫华，参上。",
  ["$A_YS__xiabu4"] = "刀剑抱业，名工怀宝。",
  ["$A_YS__xiabu5"] = "我会珍惜这一份幸运。",
  ["$A_YS__xiabu6"] = "寻珍觅奇…也算得一种雅趣。",
  ["$YS__sllh_win_audio"] = "呵呵…今日运势不错。",
  ["~YS__sllh"] = "失态了…",
}


local YS__shgxh = General(extension, "YS__shgxh", "Hydro", 4, 4, General.Female)
local YS__shgxhwin = fk.CreateActiveSkill{ name = "YS__shgxh_win_audio" }
YS__shgxhwin.package = extension
Fk:addSkill(YS__shgxhwin)
Fk:addPoxiMethod{
  name = "YS__haiyuechoose",
  card_filter = function(to_select, selected, data)
    return #selected == 0
  end,
  feasible = function(selected)
    return #selected == 1
  end,
  prompt = function ()
    return "海染：选择一张海月"
  end
}
local YS__haiyue = fk.CreateActiveSkill{
  name = "YS__haiyue",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isNude()
  end,
  card_filter = function(self, to_select, selected, targets)
    if #selected == 1 then
      return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip and Fk:getCardById(to_select).suit == Fk:getCardById(selected[1]).suit
    elseif #selected == 2 then
      return false
    end
    return Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected_cards == 1 then
      return #selected == 0 and #Fk:currentRoom():getPlayerById(to_select):getPile("YS__haiyue") < 3 and Fk:currentRoom():getPlayerById(to_select):getMark("YS__haiyue-phase") == 0
    end
    if #selected_cards == 2 then
      return #selected == 0 and #Fk:currentRoom():getPlayerById(to_select):getPile("YS__haiyue") < 2 and Fk:currentRoom():getPlayerById(to_select):getMark("YS__haiyue-phase") == 0
    end
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    target:addToPile("YS__haiyue", effect.cards, false, self.name)
    room:setPlayerMark(target, "YS__haiyue-phase", 1)
  end
}
local YS__haiyueRecover = fk.CreateTriggerSkill{
  name = "#YS__haiyueRecover",
  anim_type = "support",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead and #target:getPile("YS__haiyue") > 0 and target:getMark("YS__haiyue-turn") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local s = room:askForSkillInvoke(target, self.name, nil, "是否发动海月")
    if s then
      local card = player.room:askForCard(target, 1, 1, false, "YS__haiyue", true, ".|.|.|YS__haiyue", "你可以获得一张海月然后回复一点体力", "YS__haiyue")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:moveCardTo(self.cost_data, Card.PlayerHand, target, fk.ReasonGive, self.name, "YS__haiyue", true, target.id)
    room:recover({
      who = target,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    room:setPlayerMark(target, "YS__haiyue-turn", 1)
  end,
}
local YS__haiyueRecover2 = fk.CreateTriggerSkill{
  name = "#YS__haiyueRecover2",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return not target.dead and #target:getPile("YS__haiyue") > 0 and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and target:getMark("YS__haiyue-turn") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local s = room:askForSkillInvoke(target, self.name, nil, "是否发动海月")
    if s then
      local card = player.room:askForCard(target, 1, 1, false, "YS__haiyue", true, ".|.|.|YS__haiyue", "你可以获得一张海月然后回复一点体力", "YS__haiyue")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:moveCardTo(self.cost_data, Card.PlayerHand, target, fk.ReasonGive, self.name, "YS__haiyue", true, target.id)
    room:recover({
      who = target,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    room:setPlayerMark(target, "YS__haiyue-turn", 1)
  end,
}
local YS__huayv = fk.CreateTriggerSkill{
  name = "YS__huayv",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      player.phase == Player.Start
  end,
  can_wake = function(self, event, target, player, data)
    return #player:getPile("YS__haiyue") > 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(player, "YS__hairan", nil)
  end
}
local YS__hairan = fk.CreateViewAsSkill{
  name = "YS__hairan",
  pattern = "slash",
  mute = true,
  view_as = function(self, cards)
    local card = Fk:cloneCard("YS__water__slash")
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p)
      return #p:getPile("YS__haiyue") ~= 0
    end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "选择一名有海月的角色", self.name, false, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        room:setPlayerMark(to, "huixue", 1)
        if #to:getPile("YS__haiyue") ~= 0 then
          local target_e = to:getCardIds(Player.Special, "YS__haiyue")
          local card = room:askForPoxi(player, "YS__haiyuechoose", {
          { to.general, target_e },
          }, nil, true)
          player.room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, "YS__haiyue", true, player.id)
          if room:getCardOwner(card[1]) == player and room:getCardArea(card[1]) == Player.Hand then
            use.card:addSubcard(card[1])
            use.extraUse = true
            return
          end
        end
      end
    end
    return ""
  end,
  enabled_at_play = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function(p)
      return #p:getPile("YS__haiyue") ~= 0 end) and player:canUse(Fk:cloneCard("YS__water__slash"))
  end,
  enabled_at_response = function(self, player)
    local pat = Fk.currentResponsePattern
    return pat and table.find(Fk:currentRoom().alive_players, function(p)
      return (Exppattern:Parse(pat):matchExp("slash") and #p:getPile("YS__haiyue") ~= 0)
    end)
  end,
}
local YS__hairan_delay = fk.CreateTriggerSkill{
  name = "#YS__hairan_delay",
  mute = true,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card and table.contains(data.card.skillNames, "YS__hairan") and player.phase == Player.Play
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local rand = math.random(1, 3)
    if rand == 1 then
      player:broadcastSkillInvoke("YS__hairan", 1)
    elseif rand == 2 then
      player:broadcastSkillInvoke("YS__hairan", 2)
    else
      player:broadcastSkillInvoke("YS__hairan", 3)
    end
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("huixue") ~= 0
    end), function(p)
      return p.id
    end)
    for _, targetId in ipairs(availableTargets) do
      local ta = room:getPlayerById(targetId)
      if ta:isWounded() then
        room:recover({
          who = ta,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
        room:setPlayerMark(ta, "huixue", 0)
      elseif not ta:isWounded() then
        ta:drawCards(1)
        room:setPlayerMark(ta, "huixue", 0)
      end
    end
    if player:isWounded() then
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    if not player:isWounded() and player:getMark("huixue") ~= 0 then
      player:drawCards(1)
    end
    if player:isWounded() and player:getMark("huixue") ~= 0 then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
    elseif not player:isWounded() then
      player:drawCards(1)
      if player:getMark("huixue") ~= 0 then
        player:drawCards(1)
      end
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card and table.contains(data.card.skillNames, "YS__hairan") and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "huixue", 0)
    local room = player.room
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("huixue") ~= 0
    end), function(p)
      return p.id
    end)
    for _, targetId in ipairs(availableTargets) do
      local ta = room:getPlayerById(targetId)
      room:setPlayerMark(ta, "huixue", 0)
    end
  end,
}
YS__hairan:addRelatedSkill(YS__hairan_delay)
YS__haiyue:addRelatedSkill(YS__haiyueRecover)
YS__haiyue:addRelatedSkill(YS__haiyueRecover2)
YS__shgxh:addSkill(YS__haiyue)
YS__shgxh:addSkill(YS__huayv)
YS__shgxh:addRelatedSkill(YS__hairan)
Fk:loadTranslationTable{
  ["YS__shgxh"] = "珊瑚宫心海",
  ["YS__haiyue"] = "<font color='#66B3FF'>海月</font>",
  ["#YS__haiyueRecover"] = "海月",
  ["#YS__haiyueRecover2"] = "海月",
  ["YS__huayv"] = "化羽",
  ["YS__hairan"] = "海染",
  [":YS__haiyue"] = "出牌阶段每名角色限一次，你可以将至多两张同花色的手牌置于一名角色的武将牌上称为“海月”（上限为3）；每回合每名角色限一次，有“海月”的角色受到伤害或出牌阶段开始时，其可以获得一张“海月”然后回复一点体力。",
  [":YS__huayv"] = "觉醒技，准备阶段，若你拥有不小于3的“海月”，你减少一点体力上限，获得〖海染〗。",
  [":YS__hairan"] = "你可以将场上一张“海月”当雷【杀】使用或打出，你以此法使用的雷【杀】不计入次数；若此【杀】造成伤害，则你和拥有此“海月”的角色各回复一点体力，若未受伤则改为摸一张牌。",
  ["$YS__haiyue1"] = "帮帮忙！",
  ["$YS__haiyue2"] = "别担心。",
  ["$YS__haiyue3"] = "休养生息。",
  ["$YS__huayv1"] = "沧海之约。",
  ["$YS__huayv2"] = "翻涌吧！",
  ["$YS__huayv3"] = "深海的加护！",
  ["$YS__hairan1"] = "援军已至！",
  ["$YS__hairan2"] = "补给可是头等要事。",
  ["$YS__hairan3"] = "未雨绸缪，才能临危不乱。",
  ["$YS__shgxh_win_audio"] = "沧海月明，潮起潮落。力量更进一步，心境也会有所不同。",
  ["~YS__shgxh"] = "不会再犯同样的错误。",
}



---@param player ServerPlayer @ 发起整肃的玩家
---@param target ServerPlayer @ 获得奖励的玩家
---@param reward string|null @ 要获得的奖励（"draw2"|"recover"）
---@param skillName string @ 技能名
--获得整肃奖励
local function RewardZhengsu(player, target, reward, skillName)
  reward = reward or "风咏"
  local room = player.room
  if reward == "风咏" then
    room:setPlayerMark(target,"@@fengyong", 1)
  elseif reward == "霞立" then
    room:setPlayerMark(target,"@@xiali",1)
    target:throwAllCards("j")
  elseif reward == "相闻" then
    room:setPlayerMark(target,"@xiangwen",2)
  end
end

local YS__fywy = General(extension, "YS__fywy", "Anemo", 3, 3, General.Male)
local YS__fywywin = fk.CreateActiveSkill{ name = "YS__fywy_win_audio" }
YS__fywywin.package = extension
Fk:addSkill(YS__fywywin)
local YS__luanlan = fk.CreateTriggerSkill{
  name = "YS__luanlan",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.EventPhaseStart then
        return player:hasSkill(self) and player.phase == Player.Play
      else
        return player.phase == Player.Discard and not player.dead and
        player:usedSkillTimes(self.name, Player.HistoryTurn) > 0 and
        checkZhengsu(player, target, self.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "乱岚：你可以进行“整肃”，若成功，则弃牌阶段结束后你可以令一名角色获得奖励，然后你获得“拨止”直到你下回合准备阶段开始。")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      startZhengsu(player, player, self.name, "乱岚：选择你本回合“整肃”的条件")
      local rand = math.random(1, 3)
      if rand == 1 then
        player:broadcastSkillInvoke("YS__luanlan", 1)
      elseif rand == 2 then
        player:broadcastSkillInvoke("YS__luanlan", 2)
      else
        player:broadcastSkillInvoke("YS__luanlan", 8)
      end
    else
      local room = player.room
      local choices = {"风咏","霞立","相闻"}
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function (p)
        return p.id end), 1, 1, "乱岚：你可以令一名角色获得整肃奖励", self.name, true)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        local reward = room:askForChoices(player, choices, 2, 2, self.name, "#YS__luanlan-support::"..to.id, false, nil, {"风咏","霞立","相闻"})
        player:broadcastSkillInvoke("YS__luanlan", math.random(4,6))
        RewardZhengsu(player, to, reward[1], self.name)
        RewardZhengsu(player, to, reward[2], self.name)
        room:setPlayerMark(player, "@@YS__pozhi", 1)
      end
    end
  end,
  priority = 3,
}
local YS__luanlan_trigger = fk.CreateTriggerSkill{
  name = "#YS__luanlan_trigger",
  mute = true,
  events = {fk.DrawNCards, fk.EventPhaseStart, fk.Damaged, fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.DrawNCards then
        return player:getMark("@xiangwen") ~= 0
      elseif event == fk.EventPhaseStart then
        return player.phase == Player.Play and (player:getMark("@@fengyong") ~= 0 or player:getMark("@@xiali") ~= 0)
      elseif event == fk.Damaged then
        return player:getMark("@xiangwen") ~= 0
      elseif event == fk.DamageCaused then
        return player:getMark("@@fengyong") ~= 0
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local src = table.find(room.alive_players, function(p) return p:hasSkill("YS__luanlan", true) end)
    if event == fk.DrawNCards then
      if src then
        src:broadcastSkillInvoke("YS__luanlan", 5)
        room:notifySkillInvoked(src, "YS__luanlan", "support")
      end
      data.n = data.n + player:getMark("@xiangwen")
      if src ~= nil and src ~= player then
        player:broadcastSkillInvoke("YS__luanlan", 7)
        src:drawCards(player:getMark("@xiangwen"))
      end
    elseif event == fk.EventPhaseStart then
      if src then
        src:broadcastSkillInvoke("YS__luanlan", math.random(5, 6))
        room:notifySkillInvoked(src, "YS__luanlan", "support")
      end
      if player:getMark("@@xiali") ~= 0 then
        room:addPlayerMark(player, MarkEnum.SlashResidue.."-phase", 2)
      end
      if player:getMark("@@fengyong") ~= 0 then
        local cid = room:askForCard(player, 1, 1, true, self.name, true, ".", "风咏：弃置一张牌获得对应属性标记")
        room:throwCard(cid, self.name, player, player)
        if Fk:getCardById(cid[1]).color == Card.Red then
          room:setPlayerMark(player,"@fire-turn", 2)
        elseif Fk:getCardById(cid[1]).color == Card.Black then
          room:setPlayerMark(player,"@thunderice-turn", 2)
        end
      end
    elseif event == fk.Damaged then
      room:addPlayerMark(player,"@xiangwen", -1)
      if data.card and target.room:getCardArea(data.card) == Card.Processing then
        player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
      end
      player:drawCards(1)
    elseif event == fk.DamageCaused then
      if src then
      if data.damageType == fk.FireDamage and player:getMark("@fire-turn") ~= 0 and data.from == player and not data.from.dead then
        data.damage = data.damage + 1
        room:addPlayerMark(player,"@fire-turn", -1)
      elseif data.damageType == (fk.ThunderDamage or fk.IceDamage) and player:getMark("@thunderice-turn") ~= 0 and data.from == player and not data.from.dead then
        data.damage = data.damage + 1
        room:addPlayerMark(player,"@thunderice-turn", -1)
      end
      end
    end
  end,

  refresh_events = {fk.EventPhaseEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@xiangwen", 0)
    player.room:setPlayerMark(player, "@@fengyong", 0)
    player.room:setPlayerMark(player, "@@xiali", 0)
  end,
}
local YS__luanlan_targetmod = fk.CreateTargetModSkill{
  name = "#YS__luanlan_targetmod",
  bypass_distances = function(self, player, skill, card, to)
    return player:getMark("@@xiali") ~= 0 and player.phase ~= Player.NotActive
  end,
}
local YS__pozhi = fk.CreateTriggerSkill{
  name = "YS__pozhi",
  anim_type = "offensive",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return player:getMark("@@YS__pozhi") ~= 0 and player.phase == Player.Start and target == player and not player:prohibitUse(Fk:cloneCard("slash"))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard "slash"
    local max_num = slash.skill:getMaxTargetNum(player, slash)
    local targets = {}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if not player:isProhibited(p, slash) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 or max_num == 0 then return end
    local tos = room:askForChoosePlayers(player, targets, 1, max_num, "视为对一名其他角色使用杀", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard "slash"
    slash.skillName = self.name
    player:broadcastSkillInvoke("YS__luanlan", math.random(4, 6))
    local use = {
      from = target.id,
      tos = table.map(self.cost_data, function(pid) return { pid } end),
      card = slash,
      extraUse = true,
    }
    use.card.skillName = self.name
    room:useCard(use)
    player.room:setPlayerMark(player,"@@YS__pozhi", 0)
    if not player.dead and use.damageDealt and not room:getPlayerById(self.cost_data[1]):isNude() then
      player:throwAllCards("j")
      local to = room:getPlayerById(self.cost_data[1])
      local C = {}
      if not to:isNude() then
        table.insert(C, "qzb")
        table.insert(C, "qsp")
      end
      local CS = room:askForChoice(player, C, self.name)
      if CS == "qzb" then
        to:throwAllCards("e")
      elseif CS == "qsp" then
        U.viewCards(player, to:getCardIds("h"))
        local choices = {}
        if table.find(to:getCardIds("h"), function(id) return Fk:getCardById(id).color == Card.Red end) then
          table.insert(choices, "red")
        end
        if table.find(to:getCardIds("h"), function(id) return Fk:getCardById(id).color == Card.Black end) then
          table.insert(choices, "black")
        end
        local choice = room:askForChoice(player, choices, self.name, "弃置其手牌中一种颜色的牌")
        room:throwCard(table.filter(to:getCardIds("h"), function(id)
          return Fk:getCardById(id):getColorString() == choice end), self.name, to, to)
      end
    end
  end,

  refresh_events = {fk.PreCardEffect},
  can_refresh = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, self.name)
  end,
  on_refresh = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.YS__pozhi = 2
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    data.fixedResponseTimes["jink"] = data.extra_data.YS__pozhi
  end,
}
local YS__pozhi_Noactive = fk.CreateTriggerSkill{
  name = "#YS__pozhi_Noactive",
  anim_type = "defence",
  events = {fk.Damaged},
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@YS__pozhi") ~= 0 and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__pozhi", 1)
    player.room:setPlayerMark(player,"@@YS__pozhi", 0)
  end,
  priority = 2,

  refresh_events = {fk.TargetSpecified, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      return (data.extra_data or {}).YS__pozhiNullified
    else
      return table.contains(data.card.skillNames, "YS__pozhi") and room:getPlayerById(data.to):isAlive()
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      for key, num in pairs(data.extra_data.YS__pozhiNullified) do
        local p = room:getPlayerById(tonumber(key))
        if p:getMark(fk.MarkArmorNullified) > 0 then
          room:removePlayerMark(p, fk.MarkArmorNullified, num)
        end
      end

      data.YS__pozhiNullified = nil
    else
      room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)

      data.extra_data = data.extra_data or {}
      data.extra_data.YS__pozhiNullified = data.extra_data.YS__pozhiNullified or {}
      data.extra_data.YS__pozhiNullified[tostring(data.to)] = (data.extra_data.YS__pozhiNullified[tostring(data.to)] or 0) + 1
    end
  end,
}

local YS__yidao = fk.CreateActiveSkill{
  name = "YS__yidao",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(2, self.name)
    local cards = room:askForDiscard(player, 3, 3, true, self.name, false, ".", "一刀：弃置三张牌，可以触发额外效果。")
    local typeMap = {}
    for _, id in ipairs(cards) do
      typeMap[tostring(Fk:getCardById(id).type)] = (typeMap[tostring(Fk:getCardById(id).type)] or 0) + 1
    end
    for _, v in pairs(typeMap) do
      if v >= 2 then
      player:setMark("restop-turn",1)
      end
    end
    local colorMap = {}
    for _, id in ipairs(cards) do
      colorMap[tostring(Fk:getCardById(id).color)] = (colorMap[tostring(Fk:getCardById(id).color)] or 0) + 1
    end
    for _, v in pairs(colorMap) do
      if v == 3 then
      player:setMark("give-turn",1)
      end
    end
    local suitMap = {}
    for _, id in ipairs(cards) do
      suitMap[tostring(Fk:getCardById(id).suit)] = (suitMap[tostring(Fk:getCardById(id).suit)] or 0) + 1
    end
    for _, v in pairs(suitMap) do
      if v >= 2 then
      player:setMark("suitstop-turn",1)
      end
    end
    if player:getMark("restop-turn") == 0 then
      player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
    end
    if player:getMark("give-turn") == 1 then
      local move = room:askForYiji(player, cards, room:getOtherPlayers(player), self.name, 0, 3, nil, cards, true, 3)
      room:doYiji(move, player.id, self.name)
    end
    if player:getMark("suitstop-turn") == 0 then
      local availableTargets = table.map(table.filter(room:getOtherPlayers(player), function(p)
        return not p:isNude()
      end), Util.IdMapper)
      if #availableTargets == 0 then return false end
      local targets = room:askForChoosePlayers(player, availableTargets, 1, 1, "弃置一名其他角色两张牌", self.name, true)
      if #targets > 0 then
        player.room:doIndicate(player.id, targets)
        local to = player.room:getPlayerById(targets[1])
        room:askForDiscard(to, 2, 2, true, self.name, false, ".", "一刀：弃置两张牌")
      end
    end
  end,
}
local xiali_prohibit = fk.CreateProhibitSkill{
  name = "#xiali_prohibit",
  frequency = Skill.Compulsory,
  mute = true,
  is_prohibited = function(self, from, to, card)
    return to:getMark("@@xiali") ~= 0 and card and card.sub_type == Card.SubtypeDelayedTrick
  end,
}
YS__fywy:addSkill(YS__luanlan)
YS__luanlan:addRelatedSkill(YS__luanlan_trigger)
YS__luanlan:addRelatedSkill(YS__luanlan_targetmod)
YS__fywy:addSkill(YS__yidao)
YS__fywy:addSkill(YS__pozhi)
YS__pozhi:addRelatedSkill(YS__pozhi_Noactive)
YS__luanlan:addRelatedSkill(xiali_prohibit)
Fk:loadTranslationTable{
  ["YS__fywy"] = "枫原万叶",
  ["YS__luanlan"] = "乱岚",
  ["#YS__luanlan_trigger"] = "乱岚",
  ["YS__yidao"] = "一刀",
  [":YS__yidao"] = "出牌阶段限一次，你可以摸两张牌然后弃置三张牌，若你以此法弃置的牌：颜色相同，你可以为其他角色分配你弃置的牌；花色不同，你可以令一名其他角色弃置两张牌；类别不同，你视为未发动此技能。",
  ["YS__pozhi"] = "拨止",
  [":YS__pozhi"] = "准备阶段，你可以视为使用一张无距离限制无视目标防具且需要两张闪抵消的【杀】，若此【杀】造成伤害，你弃置判定区里所有的牌然后你可以选择一项：1.弃置目标装备区里所有的牌；2.观看目标手牌弃置其中一种颜色的牌。如此做，你失去〖拨止〗。当你受到伤害时，你失去〖拨止〗。",
  ["@xiangwen"] = "<font color='#1AFD9C'>相闻</font>",
  ["@@xiali"] = "<font color='#1AFD9C'>霞立</font>",
  ["@@fengyong"] = "<font color='#1AFD9C'>风咏</font>",
  ["#YS__luanlan-support"] = "令%dest获得一种标记",
  ["@fire-turn"] = "<font color='Red'>火</font>",
  ["@thunderice-turn"] = "<font color='Blue'>雷</font><font color='#95CACA'>冰</font>",
  ["@@YS__pozhi"] = "拨止",
  ["qsp"] = "弃置其手牌中一种颜色的牌",
  ["qzb"] = "弃置其装备区里所有的牌",
  [":YS__luanlan"] = "出牌阶段开始时，你可以进行“整肃”，弃牌阶段结束后，若“整肃”成功，你令一名角色获得“整肃”奖励，然后你获得“拨止”"..
  "<br/><font color='grey'>#\"<b>整肃</b>\"<br/>"..
  "<b>整肃奖励：</b>直到下回合出牌阶段结束，获得“风咏”,“霞立”,“相闻”其中两种。<br/>"..
  "<b>风咏：</b>出牌阶段开始时，你可以弃置一张牌，根据弃置牌的颜色获得对应的属性标记（红色：火；黑色：雷冰），每回合限两次，当你造成对应属性伤害时，此伤害+1。<br/>"..
  "<b>霞立：</b>出牌阶段，你的出杀次数+2且使用牌无距离限制。获得此标记时，弃置判定区里所有的牌且无法成为延迟锦囊的目标。<br/>"..
  "<b>相闻：</b>摸牌阶段你与整肃发起者额外摸等同于相闻标记数量的牌，当你受到伤害时你摸一张牌并获得对你造成伤害的牌，然后你失去一个相闻标记。（初始2个标记）<br/>",
  ["$YS__luanlan1"] = "嘿！",
  ["$YS__luanlan2"] = "起！",
  ["$YS__luanlan3"] = "保持专注！",
  ["$YS__luanlan4"] = "御风而行。",
  ["$YS__luanlan5"] = "朔风解意。",
  ["$YS__luanlan6"] = "往返自然！",
  ["$YS__luanlan7"] = "天地的馈赠。",
  ["$YS__luanlan8"] = "踏风！",
  ["$YS__yidao1"] = "风共云行。",
  ["$YS__yidao2"] = "可叹，落叶飘零。",
  ["$YS__yidao3"] = "云隐…雁鸣！",
  ["$YS__pozhi1"] = "静心凝神。",
  ["~YS__fywy"] = "深感遗憾…",
  ["$YS__fywy_win_audio"] = "这把刀，更加锋利了。",
}

local YS__xg = General(extension, "YS__xg", "Pyro", 3, 3, General.Female)
local YS__xgwin = fk.CreateActiveSkill{ name = "YS__xg_win_audio" }
YS__xgwin.package = extension
Fk:addSkill(YS__xgwin)
local YS__huowu = fk.CreateActiveSkill{
  name = "YS__huowu",
  mute = true,
  anim_type = "offensive",
  target_num = 0,
  card_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:getMark("YS__huowu_used") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke("YS__huowu", math.random(1,3))
    player:drawCards(2, self.name)
    room:setPlayerMark(player, "@@YS__huowu", 1)
    room:setPlayerMark(player, "YS__huowu_used", 1)
    player.room:setPlayerMark(player, "@#YS__huowu_trigger", 0)
  end,
}
local YS__huowu_filter = fk.CreateFilterSkill{
  name = "#YS__huowu_filter",
  mute = true,
  card_filter = function(self, to_select, player)
    if player:hasSkill("YS__huowu") and player.phase == Player.Play and
    table.contains(player.player_cards[Player.Hand], to_select.id) then
      if player:getMark("@@YS__huowu") == 1 then
        return to_select.trueName == "slash"
      end
    end
  end,
  view_as = function(self, to_select, player)
    local card
    if player:getMark("@@YS__huowu") == 1 then
      card = Fk:cloneCard("fire__slash", to_select.suit, to_select.number)
    end
    card.skillName = "YS__huowu"
    return card
  end,
}
local YS__xg_attackrange = fk.CreateAttackRangeSkill{
  name = "#YS__xg_attackrange",
  correct_func = function (self, from, to)
    if from:hasSkill(self) then
    return from:getMark("@#YS__huowu_trigger")
    end
  end,
}
local YS__huowu_play = fk.CreateTriggerSkill{
  name = "#YS__huowu_play",
  mute = true,
  refresh_events = {fk.TurnStart, fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return player == target and player:getMark("YS__huowu_used") > 0
    else
      return player == target and player.phase == Player.Finish and player:getMark("YS__huowu_removed-turn") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnStart then
      room:setPlayerMark(player, "YS__huowu_removed-turn", 1)
    else
      room:setPlayerMark(player, "YS__huowu_used", 0)
    end
  end,
}
local YS__huowu_trigger = fk.CreateTriggerSkill{
  name = "#YS__huowu_trigger",
  anim_type = "drawcard",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      player:hasSkill(self) and
      player:getMark("@@YS__huowu") ~= 0 and
      player:getMark("@" .. self.name) % 3 == 0
  end,
  on_use = function(self, event, player, target, data)
    local room = player.room
    local count = player:getMark("@" .. self.name)
    local randomCard = player.room:getCardsFromPileByRule(".|.|.|.|fire__slash")
    if #randomCard > 0 then
      local ta = room:askForChoosePlayers(player, table.map(player.room.alive_players, function (p)
        return p.id end), 1, 1, "令一名角色随机获得牌堆中一张火杀", self.name, false)
      player.room:moveCards({
        ids = { randomCard[1] },
        to = ta[1],
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
        skillName = self.name,
        moveMark = "@@YSyanxiao-inhand",
      })
      player:broadcastSkillInvoke("YS__huowu", math.random(4,6))
    end
    if count == 9 then
      player.room:setPlayerMark(player, "@" .. self.name, 0)
      player.room:setPlayerMark(player, "@@YS__huowu", 0)
    end
  end,

  refresh_events = {fk.CardUsing, fk.CardResponding, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      return target == player and data == self
    end
    return player:hasSkill(self) and target == player and player:getMark("@@YS__huowu") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventLoseSkill then
      player.room:setPlayerMark(player, "@" .. self.name, 0)
    end
      player.room:addPlayerMark(player, "@" .. self.name, 1)
  end,
}
local YS__huowu_targetmod = fk.CreateTargetModSkill{
  name = "#YS__huowu_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@YSyanxiao-inhand") > 0
  end,
}
Fk:addQmlMark{
  name = "YS__xg__xieli",
  qml_path = function(name, value, p)
    return "packages/mougong/qml/XiejiBox"
  end,
  how_to_show = function(name, value, p)
    if type(value) == "table" then
      local target = Fk:currentRoom():getPlayerById(value[1])
      if target then return Fk:translate("seat#" .. target.seat) end
    end
    return " "
  end,
}
local YS__liujin = fk.CreateTriggerSkill{
  name = "YS__liujin",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.Start and player:getMark("@[YS__xg__xieli]") == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "琉金：选择一名角色为协力目标。", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("YS__huowu", math.random(4,5))
    room:notifySkillInvoked(player, self.name, "support")
    local to = room:getPlayerById(self.cost_data)
    local choices = {"xieli_tongchou", "xieli_bingjin", "xieli_shucai", "xieli_luli"}
    local choice = room:askForChoice(player, choices, self.name, "琉金：选择一名其他角色，与其进行“协力”", true)
    room:setPlayerMark(player, "@[YS__xg__xieli]", {to.id, choice, room.logic:getCurrentEvent().id})
  end,

  refresh_events = {fk.AfterTurnEnd, fk.Death},
  can_refresh = function (self, event, target, player, data)
    local mark = player:getTableMark("@[YS__xg__xieli]")
    return #mark > 0 and mark[1] == target.id
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@[YS__xg__xieli]", 0)
  end,
}
local YS__liujin_delay = fk.CreateTriggerSkill{
  name = "#YS__liujin_delay",
  events = {fk.TurnEnd, fk.DamageCaused, fk.TargetSpecified},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      if not player.dead and target ~= player and not player:prohibitUse(Fk:cloneCard("slash")) then
        local mark = player:getTableMark("@[YS__xg__xieli]")
        if #mark == 0 then return false end
        local pid = mark[1]
        if pid == target.id then
          local choice = mark[2]
          local event_id = mark[3]
          if choice == "xieli_tongchou" then
            local n = 0
            local events =  room.logic:getActualDamageEvents(999, function(e) return e.data[1].from == player or e.data[1].from == target end, nil, event_id)
            for _, e in ipairs(events) do
              n = n + e.data[1].damage
            end
            return n >= 4
          elseif choice == "xieli_bingjin" then
            local n = 0
            room.logic:getEventsByRule(GameEvent.MoveCards, 999, function(e)
              for _, move in ipairs(e.data) do
                if move.moveReason == fk.ReasonDraw and (move.to == player.id or move.to == target.id) then
                  for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.DrawPile then
                      n = n + 1
                    end
                  end
                end
              end
              return false
            end, event_id)
            return n >= 8
          elseif choice == "xieli_shucai" then
            local suits = {}
            room.logic:getEventsByRule(GameEvent.MoveCards, 999, function(e)
              for _, move in ipairs(e.data) do
                if move.moveReason == fk.ReasonDiscard and (move.from == player.id or move.from == target.id) then
                  for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                      local suit = Fk:getCardById(info.cardId).suit
                      if suit ~= Card.NoSuit then
                        table.insertIfNeed(suits, suit)
                      end
                    end
                  end
                end
              end
              return false
            end, event_id)
            return #suits == 4
          elseif choice == "xieli_luli" then
            local suits = {}
            room.logic:getEventsByRule (GameEvent.UseCard, 999, function(e)
              for _, move in ipairs(e.data) do
                local use = e.data[1]
                if use.from == player.id or use.from == target.id then
                  local suit = use.card.suit
                  if suit ~= Card.NoSuit then
                    table.insertIfNeed(suits, suit)
                  end
                end
              end
              return false
            end, event_id)
            room.logic:getEventsByRule(GameEvent.RespondCard, 999, function(e)
              for _, move in ipairs(e.data) do
                local resp = e.data[1]
                if resp.from == player.id or resp.from == target.id then
                  local suit = resp.card.suit
                  if suit ~= Card.NoSuit then
                    table.insertIfNeed(suits, suit)
                  end
                end
              end
              return false
            end, event_id)
            return #suits == 4
          end
        end
      end
    else
      return target == player and not player.dead and data.card and table.contains(data.card.skillNames, "YS__liujin")
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      player:broadcastSkillInvoke(self.name, math.random(1,3))
      room:notifySkillInvoked(player, "YS__liujin", "offensive")
      local slash = Fk:cloneCard("slash")
      slash.skillName = "YS__liujin"
      local targets = table.filter(room:getOtherPlayers(player), function (p) return not player:isProhibited(p, slash) end)
      if #targets == 0 then return false end
      local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "你可以使用一张无距离限制且不可响应的火杀。", "YS__liujin", true)
      if #tos > 0 then
        room:useVirtualCard("fire__slash", nil, player, table.map(tos, Util.Id2PlayerMapper), "YS__liujin", true)
      end
    end
    if event == fk.TargetSpecified then
      data.disresponsive = true
    end
    if event == fk.DamageCaused then
      local targets = {}
            for _, p in ipairs(room.alive_players) do
              if p ~= player and p:getMark("@@huoguang") ~= 0 then
                table.insert(targets, p.id)
              end
            end
      if #targets == 0 then
        room:setPlayerMark(data.to, "@@huoguang", 1)
      else
        for _, p in ipairs(room.alive_players) do
          if p ~= player and p:getMark("@@huoguang") ~= 0 then
            room:setPlayerMark(p, "@@huoguang", 0)
          end
        end
        room:setPlayerMark(data.to, "@@huoguang", 1)
      end
    end
  end,
}
local huoguang_delay = fk.CreateTriggerSkill{
  name = "#huoguang_delay",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local to = data.to
    local from = data.from
    if from ~= nil then
    return to:getMark("@@huoguang") ~= 0 and target == from and player:hasSkill(self)
    end
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local from = data.from
    if from ~= nil and player ~= from then
      if player.room:askForSkillInvoke(player, "#huoguang_delay", nil, "#houguang_invoke::"..data.from.id) then
        from:drawCards(data.damage)
      end
    end
  end,

  refresh_events = {fk.AfterDying, fk.Death},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterDying then
        return target ~= player and target:getMark("@@huoguang") ~= 0 and player.room:askForSkillInvoke(player, self.name, nil, "是否触发“火光”")
      else
        return target:getMark("@@huoguang") ~= 0 and player.room:askForSkillInvoke(player, self.name, nil, "是否触发“火光”")
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterDying and not target.dead and target:getMark("@@huoguang") ~= 0 then
      player.room:doIndicate(player.id, {target.id})
      room:setPlayerMark(target, "@@huoguang", 0)
      player.room:damage{
        from = player,
        to = target,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name,
      }
      player:broadcastSkillInvoke("YS__liujin", math.random(2,3))
    end
    if event == fk.Death then
      local dra_tars = table.filter(room.alive_players, function(p) return p ~= player end)
      if #dra_tars > 0 then
      local tos = room:askForChoosePlayers(player, table.map(dra_tars, Util.IdMapper), 1, 1, "选择一名其他角色转移“火光”", self.name, true)
        if #tos > 0 then
          player:broadcastSkillInvoke("YS__liujin", math.random(2,3))
          room:setPlayerMark(room:getPlayerById(tos[1]), "@@huoguang", 1)
        end
      end
    end
  end,
}

YS__xg:addSkill(YS__huowu)
YS__huowu:addRelatedSkill(YS__huowu_filter)
YS__huowu:addRelatedSkill(YS__huowu_play)
YS__huowu:addRelatedSkill(YS__huowu_trigger)
YS__huowu:addRelatedSkill(YS__xg_attackrange)
YS__huowu:addRelatedSkill(YS__huowu_targetmod)
YS__xg:addSkill(YS__liujin)
YS__liujin:addRelatedSkill(YS__liujin_delay)
YS__liujin:addRelatedSkill(huoguang_delay)
Fk:loadTranslationTable{
  ["YS__xg"] = "宵宫",
  ["YS__huowu"] = "火舞",
  [":YS__huowu"] = "出牌阶段限一次，你可以摸两张牌并获得“火舞”标记，然后此技能失效直到下个回合结束阶段；<br><em>“火舞”：你的【杀】均视为火【杀】。每使用或打出一张牌后你的攻击距离+1；三张牌后，令一名角色从牌堆中随机获得一张无次数限制的火【杀】，触发3次后弃置火舞标记。</em>",
  ["#YS__xg__slash"] = "火舞",
  ["YS__liujin"] = "琉金",
  [":YS__liujin"] = "准备阶段，你可以选择一名其他角色，与其进行一次“协力”。<br>该角色的回合结束时，若你与其“协力”成功，你可以视为对一名其他角色使用一张无法响应的火【杀】，此【杀】造成伤害后，其获得“火光”。<br>有“火光”的角色进入濒死状态结算后，若其未死亡，则你可以弃置“火光”对其造成一点火焰伤害；若其死亡，则你可以转移“火光”（场上最多存在一个“火光”）。<br>当除你外的其他角色对有“火光”的角色造成伤害后，你可以令其摸等同于伤害数的牌。",
  ["@@YS__huowu"] = "<font color='#FF7575'>火舞</font>",
  ["@@huoguang"] = "<font color='#FF2D2D'>火光</font>",
  ["@#YS__huowu_trigger"] = "<font color='#CE0000'>焰硝</font>",
  ["@@YSyanxiao-inhand"] = "焰硝箭",
  ["#YS__huowu_trigger"] = "火舞",
  ["#YS__huowu_play"] = "火舞",
  ["#YS__huowu_filter"] = "火舞",
  ["#YS__liujin_delay"] = "琉金",
  ["#huoguang_delay"] = "火光",
  ["#houguang_invoke"] = "火光:你可以令%dest摸牌",
  ["$YS__huowu1"] = "点燃引信！",
  ["$YS__huowu2"] = "想看烟花吗?",
  ["$YS__huowu3"] = "小心火烛！",
  ["$YS__huowu4"] = "你想办祭典吗?",
  ["$YS__huowu5"] = "一起去玩吧！",
  ["$YS__huowu6"] = "会有烟花材料吗?",
  ["$YS__liujin1"] = "祭典重现！",
  ["$YS__liujin2"] = "金鱼来啦！",
  ["$YS__liujin3"] = "烟花来喽！",
  ["$YS__xg_win_audio"] = "「『英雄形态』的宵宫姐姐登场！邪恶退散！正义必胜！」",
  ["~YS__xg"] = "玩过头了…",

  ["@[YS__xg__xieli]"] = "协力",
  ["xieli_tongchou"] = "同仇",
  [":xieli_tongchou"] = "你与其造成的伤害值之和不小于4",
  ["xieli_bingjin"] = "并进",
  [":xieli_bingjin"] = "你与其总计摸过至少8张牌",
  ["xieli_shucai"] = "疏财",
  [":xieli_shucai"] = "你与其弃置的牌中包含4种花色",
  ["xieli_luli"] = "勠力",
  [":xieli_luli"] = "你与其使用或打出的牌中包含4种花色",
}

local YS__sllr = General(extension, "YS__sllr", "Hydro", 4, 4, General.Male)
local YS__sllrwin = fk.CreateActiveSkill{ name = "YS__sllr_win_audio" }
YS__sllrwin.package = extension
Fk:addSkill(YS__sllrwin)
local YS__jinghua = fk.CreateTriggerSkill{
  name = "YS__jinghua",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  expand_pile = "YS__Ajianying&",
  derived_piles = "YS__Ajianying&",
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
      if player:getMark("@@YS__shuiyou") == 0 then
        local cards = room:askForCard(player, 1, 2, true, self.name, true, ".|.|.|.|.|.", "是否将至多两张牌置于武将牌上称为剑影")
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      else
        local cards = room:askForCard(player, 1, 3, true, self.name, true, ".|.|.|.|.|.", "是否将至多三张牌置于武将牌上称为剑影")
        if #cards > 0 then
          self.cost_data = cards
          return true
        end
      end
  end,
  on_use = function(self, event, target, player, data)
    local dummy = Fk:cloneCard("dilu")
    dummy:addSubcards(self.cost_data)
    player:addToPile("YS__Ajianying&", self.cost_data, true, self.name)
    player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
  end,
}
local YS__jinghua_use = fk.CreateTriggerSkill{
  name = "#YS__jinghua_use",
  mute = true,
  events = {fk.CardUsing},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@YS__shuiyou") == 0 then
    local B = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeBasic
    end)
    local T = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeTrick
    end)
    return target == player and player.phase == Player.Play and #player:getPile("YS__Ajianying&") ~= 0 and player:hasSkill(self) and
    ((#T ~= 0 and data.card.type == Card.TypeTrick and data.card:isCommonTrick()) or
    (#B ~= 0 and data.card.type == Card.TypeBasic))
    else
      return target == player and player.phase == Player.Play and #player:getPile("YS__Ajianying&") ~= 0 and (data.card:isCommonTrick() or data.card.type == Card.TypeBasic)
    end
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.YS__jinghua = data.extra_data.YS__jinghua or true
  end,
  priority = 10,
}
local YS__jinghua_trigger = fk.CreateTriggerSkill{
  name = "#YS__jinghua_trigger",
  mute = true,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@YS__shuiyou") == 0 then
    local B = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeBasic
    end)
    local T = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeTrick
    end)
    return target == player and player.phase == Player.Play and #player:getPile("YS__Ajianying&") ~= 0 and player:hasSkill(self) and
    ((#T ~= 0 and data.card.type == Card.TypeTrick and data.card:isCommonTrick()) or
    (#B ~= 0 and data.card.type == Card.TypeBasic))
    else
      return target == player and player.phase == Player.Play and #player:getPile("YS__Ajianying&") ~= 0 and (data.card:isCommonTrick() or data.card.type == Card.TypeBasic)
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, "YS__jinghua", nil, "镜花:令此牌额外结算一次") and data.extra_data and data.extra_data.YS__jinghua
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data.YS__jinghua = false
    local room = player.room
  if player:getMark("@@YS__shuiyou") == 0 then
    local B = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeBasic
    end)
    local T = table.filter(player:getPile("YS__Ajianying&"), function(id)
      local card = Fk:getCardById(id)
      return card.type == Card.TypeTrick
    end)
    if #T ~= 0 and data.card.type == Card.TypeTrick and data.card:isCommonTrick() then
      local card = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|YS__Ajianying&|.|trick", "弃置一张同类别剑影", "YS__Ajianying&")
      room:throwCard(card, self.name, player, player)
      player.room:doIndicate(player.id, {data.to})
      player:drawCards(1)
      if data.card.name == "amazing_grace" then
        local tar = table.filter(room:getAlivePlayers(), function(p)
          return not player:isProhibited(p, Fk:cloneCard("amazing_grace"))
     end)
        player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
        room:useVirtualCard("amazing_grace", nil, player, tar, self.name, true)
      else
      player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
      data.additionalEffect = (data.additionalEffect or 0) + 1
      end
    end
    if #B ~= 0 and data.card.type == Card.TypeBasic then
      local card = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|YS__Ajianying&|.|basic", "弃置一张同类别剑影", "YS__Ajianying&")
      room:throwCard(card, self.name, player, player)
      player.room:doIndicate(player.id, {data.to})
      player:drawCards(1)
      player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
      data.additionalEffect = (data.additionalEffect or 0) + 1
    end
  else
    local card = player.room:askForCard(player, 1, 1, false, self.name, false, ".|.|.|YS__Ajianying&|.|.", "弃置一张剑影", "YS__Ajianying&")
      room:throwCard(card, self.name, player, player)
      player.room:doIndicate(player.id, {data.to})
      player:drawCards(1)
      if data.card.name == "amazing_grace" then
        local tar = table.filter(room:getAlivePlayers(), function(p)
          return not player:isProhibited(p, Fk:cloneCard("amazing_grace"))
     end)
        player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
        room:useVirtualCard("amazing_grace", nil, player, tar, self.name, true)
      else
      player:broadcastSkillInvoke("YS__jinghua", math.random(1,2))
      data.additionalEffect = (data.additionalEffect or 0) + 1
      end
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@YS__shuiyou") ~= 0 and player:hasSkill(self)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@YS__shuiyou", 0)
  end,
}
Fk:addQmlMark{
  name = "YS__sllr__xieli",
  qml_path = function(name, value, p)
    return "packages/mougong/qml/XiejiBox"
  end,
  how_to_show = function(name, value, p)
    if type(value) == "table" then
      local target = Fk:currentRoom():getPlayerById(value[1])
      if target then return Fk:translate("seat#" .. target.seat) end
    end
    return " "
  end,
}
local YS__shuiyou = fk.CreateTriggerSkill{
  name = "YS__shuiyou",
  events = {fk.EventPhaseStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase == Player.Start and player:getMark("@[YS__sllr__xieli]") == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "水囿：选择一名角色为协力目标。", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, math.random(2))
    room:notifySkillInvoked(player, self.name, "support")
    local to = room:getPlayerById(self.cost_data)
    local choices = {"xieli_tongchou", "xieli_bingjin", "xieli_shucai", "xieli_luli"}
    local choice = room:askForChoice(player, choices, self.name, "水囿：选择一名其他角色，与其进行“协力”", true)
    player:broadcastSkillInvoke("YS__shuiyou", math.random(1,2))
    room:setPlayerMark(player, "@[YS__sllr__xieli]", {to.id, choice, room.logic:getCurrentEvent().id})
  end,

  refresh_events = {fk.AfterTurnEnd, fk.Death},
  can_refresh = function (self, event, target, player, data)
    local mark = player:getTableMark("@[YS__sllr__xieli]")
    return #mark > 0 and mark[1] == target.id
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@[YS__sllr__xieli]", 0)
  end,
}
local YS__sllr__xieji_delay = fk.CreateTriggerSkill{
  name = "#YS__sllr__xieji_delay",
  events = {fk.TurnEnd, fk.Damage},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      if not player.dead and target ~= player and not player:prohibitUse(Fk:cloneCard("slash")) then
        local mark = player:getTableMark("@[YS__sllr__xieli]")
        if #mark == 0 then return false end
        local pid = mark[1]
        if pid == target.id then
          local choice = mark[2]
          local event_id = mark[3]
          if choice == "xieli_tongchou" then
            local n = 0
            local events = room.logic:getActualDamageEvents(999, function(e) return e.data[1].from == player or e.data[1].from == target end, nil, event_id)
            for _, e in ipairs(events) do
              n = n + e.data[1].damage
            end
            return n >= 4
          elseif choice == "xieli_bingjin" then
            local n = 0
            room.logic:getEventsByRule (GameEvent.MoveCards, 999, function(e)
              for _, move in ipairs(e.data) do
                if move.moveReason == fk.ReasonDraw and (move.to == player.id or move.to == target.id) then
                  for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.DrawPile then
                      n = n + 1
                    end
                  end
                end
              end
              return false
            end, event_id)
            return n >= 8
          elseif choice == "xieli_shucai" then
            local suits = {}
            room.logic:getEventsByRule (GameEvent.MoveCards, 999, function(e)
              for _, move in ipairs(e.data) do
                if move.moveReason == fk.ReasonDiscard and (move.from == player.id or move.from == target.id) then
                  for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                      local suit = Fk:getCardById(info.cardId).suit
                      if suit ~= Card.NoSuit then
                        table.insertIfNeed(suits, suit)
                      end
                    end
                  end
                end
              end
              return false
            end, event_id)
            return #suits == 4
          elseif choice == "xieli_luli" then
            local suits = {}
            room.logic:getEventsByRule (GameEvent.UseCard, 999, function(e)
              for _, move in ipairs(e.data) do
                local use = e.data[1]
                if use.from == player.id or use.from == target.id then
                  local suit = use.card.suit
                  if suit ~= Card.NoSuit then
                    table.insertIfNeed(suits, suit)
                  end
                end
              end
              return false
            end, event_id)
            room.logic:getEventsByRule (GameEvent.RespondCard, 999, function(e)
              for _, move in ipairs(e.data) do
                local resp = e.data[1]
                if resp.from == player.id or resp.from == target.id then
                  local suit = resp.card.suit
                  if suit ~= Card.NoSuit then
                    table.insertIfNeed(suits, suit)
                  end
                end
              end
              return false
            end, event_id)
            return #suits == 4
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      player:broadcastSkillInvoke("YS__shuiyou", math.random(3,5))
      room:notifySkillInvoked(player, "YS__shuiyou", "defensive")
      local num = player.maxHp - player:getHandcardNum()
      if num > 0 then
        player:drawCards(num, self.name)
      end
      room:setPlayerMark(player, "@@YS__shuiyou", 1)
    end
  end,
}

YS__sllr:addSkill(YS__jinghua)
YS__jinghua:addRelatedSkill(YS__jinghua_use)
YS__jinghua:addRelatedSkill(YS__jinghua_trigger)
YS__sllr:addSkill(YS__shuiyou)
YS__shuiyou:addRelatedSkill(YS__sllr__xieji_delay)

Fk:loadTranslationTable{
  ["YS__sllr"] = "神里绫人",
  ["YS__jinghua"] = "镜花",
  [":YS__jinghua"] = "出牌阶段开始时，你可以将至多两张牌置于武将牌上称为“剑影”，当你于出牌阶段使用牌后，你可以弃置一张同类型的“剑影”并摸一张牌令此牌额外结算一次。你可以如手牌般使用或打出“剑影”。",
  ["YS__shuiyou"] = "水囿",
  [":YS__shuiyou"] = "准备阶段，你可以选择一名其他角色，与其进行一次“协力”。<br>该角色的回合结束时，若你与其“协力”成功，你将手牌摸至体力上限，然后直到你下回合结束，你修改〖镜花〗为可以将至多三张牌置于武将牌上且取消触发额外结算对“剑影”的类别限制",
  ["YS__Ajianying&"] = "<font color='#66B3FF'>剑影</font>",
  ["@@YS__shuiyou"] = "<font color='#0080FF'>水囿</font>",
  ["$YS__jinghua1"] = "剑影！",
  ["$YS__jinghua2"] = "苍流水影。",
  ["$YS__shuiyou1"] = "暗线已经布置妥当，嗯，差不多该收网了…",
  ["$YS__shuiyou2"] = "呵…余兴节目。",
  ["$YS__shuiyou3"] = "呵…安息吧。",
  ["$YS__shuiyou4"] = "秋水三尺。",
  ["$YS__shuiyou5"] = "神里流…水囿！",
  ["$YS__sllr_win_audio"] = "呵，有些人怕是要寝食难安了吧。",
  ["~YS__sllr"] = "世事无常…",

  ["@[YS__sllr__xieli]"] = "协力",
  [":xieli_tongchou"] = "你与其造成的伤害值之和不小于4",
  ["xieli_bingjin"] = "并进",
  [":xieli_bingjin"] = "你与其总计摸过至少8张牌",
  ["xieli_shucai"] = "疏财",
  [":xieli_shucai"] = "你与其弃置的牌中包含4种花色",
  ["xieli_luli"] = "勠力",
  [":xieli_luli"] = "你与其使用或打出的牌中包含4种花色",
}

local getShade = function (room, n)
  local ids = {}
  for _, id in ipairs(room.void) do
    if n <= 0 then break end
    if Fk:getCardById(id).name == "shade" then
      room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, id)
      n = n - 1
    end
  end
  while n > 0 do
    local card = room:printCard("shade", Card.Spade, 1)
    room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
    table.insert(ids, card.id)
    n = n - 1
  end
  return ids
end

local YS__ldjj = General(extension, "YS__ldjj", "Electro", 4, 4, General.Female)
local YS__ldjjwin = fk.CreateActiveSkill{ name = "YS__ldjj_win_audio" }
YS__ldjjwin.package = extension
Fk:addSkill(YS__ldjjwin)
local YS__eyao = fk.CreateTriggerSkill{
  name = "YS__eyao",
  anim_type = "drawcard",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (player.phase == Player.Start or player.phase == Player.Play)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "是否发动恶曜")
  end,
  on_use = function(self, event, target, player, data)
  local room = player.room
  if player.phase == Player.Start then
    local cids = room:getNCards(3)
    player:broadcastSkillInvoke("YS__eyao", math.random(1,3))
    room:notifySkillInvoked(player, "YS__eyao", "drawcard")
    room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name)
    local cards = {}
    for _, id in ipairs(cids) do
      local card = Fk:getCardById(id)
      if card.color == Card.Black then
        table.insert(cards, id)
      end
    end
    if #cards > 0 then
      room:delay(1000)
      local dummy = Fk:cloneCard("slash")
      dummy:addSubcards(cards)
      room:obtainCard(player, dummy, true, fk.ReasonJustMove)
    end
    cards = table.filter(cids, function (id)
      return room:getCardArea(id) == Card.Processing
    end)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonJustMove, self.name)
    end
  else
    local s = room:askForCard(player, 1, #room.alive_players, true, self.name, true, ".|.|spade,club", "选择任意张黑色牌")
    if s then
      if player:hasSkill("YS__yanshou") then
        local move = room:askForYiji(player, s, room.alive_players, self.name, 1, #s, nil, "leiyan", false, 1)
        room:doYiji(move, player.id, self.name)
        local victims = {}
        for p, c in pairs(move) do
          if #c > 0 then
            table.insert(victims, tonumber(p))
          end
        end
        room:sortPlayersByAction(victims)
        for _, pid in ipairs(victims) do
          local p = room:getPlayerById(pid)
          if not p.dead and p:getMark("@@YS__yanshou") == 0 then
            room:setPlayerMark(p, "@@leifa", 1)
          end
        end
      else
        local move = room:askForYiji(player, s, room.alive_players, self.name, 1, #s, nil, "leiyan", false)
        room:doYiji(move, player.id, self.name)
        local victims = {}
        for p, c in pairs(move) do
          if #c > 0 then
            table.insert(victims, tonumber(p))
          end
        end
        room:sortPlayersByAction(victims)
        for _, pid in ipairs(victims) do
          local p = room:getPlayerById(pid)
          if not p.dead then
            room:setPlayerMark(p, "@@leifa", 1)
          end
        end
      end
    end
  end
end,
}
local leifa_trigger = fk.CreateTriggerSkill {
  name = "#leifa_trigger",
  mute = true,
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = { fk.Damaged },
  can_trigger = function(self, event, target, player, data)
    if not data.from then return false end
    local from = data.from
    return from:getMark("@@leifa") ~= 0 and player:hasSkill(self)
        and not data.leifa and not data.chain
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    local to = data.to

    if not target.dead and room:askForSkillInvoke(player, self.name, nil, "是否发动雷罚") then
      player:broadcastSkillInvoke("YS__eyao", math.random(1,3))
      room:notifySkillInvoked(player, "YS__eyao", "offensive")
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|.",
      }
      room:judge(judge)

      if judge.card.color == Card.Red then
         if player:hasSkill("YS__yanshou") then
         room:moveCards({
          ids = getShade(room, 2),
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
          moveVisible = true,
        })
        else
          room:moveCards({
            ids = getShade(room, 3),
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonPrey,
            proposer = player.id,
            skillName = self.name,
            moveVisible = true,
          })
        end
         from:drawCards(2)
         room:setPlayerMark(from, "@@leifa", 0)
      else
        room:doIndicate(player.id, { to.id })
        room:damage({
          from = player,
          to = to,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = "leifa",
          leifa = true,
        })
        if player:hasSkill("YS__yanshou") then
        room:moveCards({
          ids = getShade(room, 2),
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
          moveVisible = true,
        })
        else
        room:moveCards({
          ids = getShade(room, 3),
          to = player.id,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonPrey,
          proposer = player.id,
          skillName = self.name,
          moveVisible = true,
        })
        end
        room:setPlayerMark(from, "@@leifa", 0)
      end
    end
  end,
}
local YS__yanshou = fk.CreateTriggerSkill{
  name = "YS__yanshou",
  mute = true,
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove and player:hasSkill(self) and not player.dead then
      for _, move in ipairs(data) do
        if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "shade" then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          local to = room:getPlayerById(move.to)
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).trueName == "shade" and table.contains(to:getCardIds("h"), info.cardId) then
              room:setCardMark(Fk:getCardById(info.cardId), "@@YS__yanshouH-inhand", 1)
              room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity)
              room:addPlayerMark(to, "@@YS__yanshou", 1)
            end
          end
        end
      end
    end
  end,
  on_lose = function(self, player)
    local room = player.room
    if table.every(room.alive_players, function (p)
      return not p:hasSkill(self, true)
    end) then
      for _, p in ipairs(room.alive_players) do
        if p:getMark("@@YS__yanshou") then
          room:setPlayerMark(p, MarkEnum.UncompulsoryInvalidity, 0)
        end
        room:setPlayerMark(p, "@@YS__yanshou", 0)
        room:setPlayerMark(p, "@@leifa", 0)
      end
    end
  end,
}
local YS__yanshou_judge = fk.CreateTriggerSkill{
  name = "#YS__yanshou_judge",
  events = {fk.AfterCardsMove},
  anim_type = "negative",
  mute = true,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from ~= player.id then
          local p = player.room:getPlayerById(move.from)
          if table.find(move.moveInfo, function(info)
            return info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId).trueName == "shade"
          end) and not table.find(p:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@YS__yanshouH-inhand") > 0 end) then
            return true
          end
        end
      end
    end
    return false
  end,
  on_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      local room = player.room
      local targets = {}
      for _, move in ipairs(data) do
        if move.from ~= player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              table.insert(targets, move.from)
            end
          end
        end
      end
      room:sortPlayersByAction(targets)
      for _, target_id in ipairs(targets) do
        if not player:hasSkill(self) then break end
        local skill_target = room:getPlayerById(target_id)
        if skill_target then
          self:doCost(event, skill_target, player, data)
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:notifySkillInvoked(player, "YS__yanshou", "negative")
      room:doIndicate(player.id, {target.id})
      for _, move in ipairs(data) do
        if move.from ~= player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              room:setCardMark(Fk:getCardById(info.cardId), "@@YS__yanshouH-inhand", 0)
            end
          end
        end
      end
      room:setPlayerMark(target, MarkEnum.UncompulsoryInvalidity, 0)
      room:setPlayerMark(target, "@@YS__yanshou", 0)
    end
  end,
  priority = 20,
}
local YS__yanshou_maxcards = fk.CreateMaxCardsSkill{
  name = "#YS__yanshou_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill(self) and card.trueName == "shade"
  end,
}
local YS__wuxiang = fk.CreateActiveSkill{
  name = "YS__wuxiang",
  frequency = Skill.Limited,
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
      if not player:hasSkill("YS__duanjue",true) then
        room:handleAddLoseSkills(player, "YS__duanjue", nil, false)
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(player, "-YS__duanjue", nil, false)
        end)
      end
  end,
}
local YS__duanjue = fk.CreateActiveSkill{
  name = "YS__duanjue",
  anim_type = "offensive",
  mute = true,
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 6
  end,
  card_filter = function(self, to_select, selected)
    return Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip and Fk:getCardById(to_select).trueName == "shade"
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  target_num = 1,
  min_card_num = 1,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local player = room:getPlayerById(effect.from)
    local cards = effect.cards
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, true)
    room:addPlayerMark(player, "YS__duanjue_cards-phase", #cards)
    room:useVirtualCard("thunder__slash", nil, player, target, "YS__duanjue", true)
    room:addPlayerMark(player, "@YS__duanjue-phase", 1)
  end,
}
local YS__duanjue_delay = fk.CreateTriggerSkill{
  name = "#YS__duanjue_delay",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("YS__duanjue_cards-phase") > 0 and target == player and not player.dead and data.card and table.contains(data.card.skillNames, "YS__duanjue")
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local marks = player:getMark("YS__duanjue_cards-phase")
    if marks >= 2 then
      if marks < 5 then
        player:broadcastSkillInvoke("YS__duanjue", math.random(2,4))
      end
      data.disresponsive = true
    end
    if marks >= 3 then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if marks >= 5 and player:getMark("@YS__duanjue-phase") ~= 5 then
      player:broadcastSkillInvoke("YS__duanjue", 1)
      data.additionalDamage = (data.additionalDamage or 0) + 1
      player.room:addPlayerMark(player, "@YS__duanjue-phase", 1)
      player:addSkillUseHistory("YS__duanjue", 1)
    end
    player.room:setPlayerMark(player, "YS__duanjue_cards-phase", 0)
  end,
}
local YS__yanshouPrey = fk.CreateTriggerSkill{
  name = "#YS__yanshouPrey",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local ids = {}
      local room = player.room
      for _, move in ipairs(data) do
        if move.toArea == Card.Void then
          if move.moveReason == fk.ReasonDiscard and move.from and move.from ~= player.id then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
              Fk:getCardById(info.cardId).trueName == "shade" and
              room:getCardArea(info.cardId) == Card.Void then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          elseif move.moveReason == fk.ReasonJudge then
            local judge_event = room.logic:getCurrentEvent():findParent(GameEvent.Judge)
            if judge_event and judge_event.data[1].who ~= player then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.Processing and Fk:getCardById(info.cardId).trueName == "shade" and
                room:getCardArea(info.cardId) == Card.Void then
                  table.insertIfNeed(ids, info.cardId)
                end
              end
            end
          end
        end
      end
      ids = U.moveCardsHoldingAreaCheck(room, ids)
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(self.cost_data)
    if #ids > 1 then
      local cards, _ = U.askforChooseCardsAndChoice(player, ids, {"OK"}, self.name,
      "是否获得影", {"get_all"}, 1, #ids)
      if #cards > 0 then
        ids = cards
      end
    end
    player:broadcastSkillInvoke("YS__yanshou", math.random(1,2))
    room:notifySkillInvoked(player, "YS__yanshou", "special")
    room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, self.name)
  end,
}
local YS__zhenshuoturn = fk.CreateTriggerSkill{
  name = "YS__zhenshuoturn",
  anim_type = "support",
  mute = true,
  events = {fk.Deathed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.damage and data.damage.from == player
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "是否发动真说")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("YS__zhenshuoturn", 1)
    room:notifySkillInvoked(player, "YS__zhenshuoturn", "special")
    local c = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,"选择一名角色", self.name, true, false)
  if c then
    local to = room:getPlayerById(c[1])
    if to then
    local choices = {"mp"}
    local wakeSkills = table.map(table.filter(to.player_skills, function(p)
        return p.frequency == Skill.Wake and to:usedSkillTimes(p.name, Player.HistoryGame) < 1
      end), function(skill)
        return skill.name
      end)
    if #wakeSkills > 0 and to:getMark("@zhenshuoW") == 0 then
      table.insert(choices, "jsj")
    end
    local skills = table.filter(to.player_skills, function(p)
      return p.frequency == Skill.Limited and to:usedSkillTimes(p.name, Player.HistoryGame) > 0
    end)
    if #skills > 0 and player:getMark("@zhenshuoL-turn") == 0 then
      table.insert(choices, "xdj")
    end
    if to:getMark("@zhenshuoT-turn") == 0 and not table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("@zhenshuoT-turn") ~= 0 end) then
      table.insert(choices, "ewhh")
    end
    local CS = room:askForChoice(player, choices, self.name, "选择一项发动真说", nil, {"mp", "ewhh", "jsj", "xdj"})

    if CS == "mp" then
      to:drawCards(3)
    elseif CS == "ewhh" then
      room:setPlayerMark(to, "@zhenshuoT-turn", 1)
    elseif CS == "jsj" then
      local choice = room:askForChoice(player, wakeSkills, self.name, "选择一个技能觉醒")
      local toWakeSkills = type(to:getMark("@zhenshuoW")) == "table" and to:getMark("@zhenshuoW") or {}
      table.insertIfNeed(toWakeSkills, choice)
      room:setPlayerMark(to, "@zhenshuoW", toWakeSkills)
      toWakeSkills = type(to:getMark(MarkEnum.StraightToWake)) == "table" and to:getMark(MarkEnum.StraightToWake) or {}
      table.insertIfNeed(toWakeSkills, choice)
      room:setPlayerMark(to, MarkEnum.StraightToWake, toWakeSkills)
    elseif CS == "xdj" then
      local skillNames = table.map(skills, function(p)
        return p.name
      end)
      local skill = room:askForChoice(player, skillNames, self.name, "选择一个限定技重置")
      to:addSkillUseHistory(skill, -1)
      room:sendLog{
        type = "#ZhenshuoReset",
        from = to.id,
        arg = skill,
      }
    end
    end
  end
  end,
}
local zhenshouWClear = fk.CreateTriggerSkill{
  name = "#zhenshouWClear",
  mute = true,
  refresh_events = {fk.BeforeTriggerSkillUse},
  can_refresh = function(self, event, target, player, data)
    return
      target == player and
      data.willUse and
      data.skill.frequency == Skill.Wake and
      type(player:getMark("@zhenshuoW")) == "table" and
      table.contains(player:getMark("@zhenshuoW"), data.skill.name)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room

    local toWakeSkills = player:getMark("@zhenshuoW")
    table.removeOne(toWakeSkills, data.skill.name)
    room:setPlayerMark(player, "@zhenshuoW", #toWakeSkills > 0 and toWakeSkills or 0)

    toWakeSkills = type(player:getMark(MarkEnum.StraightToWake)) == "table" and player:getMark(MarkEnum.StraightToWake) or {}
    table.removeOne(toWakeSkills, data.skill.name)
    room:setPlayerMark(player, MarkEnum.StraightToWake, #toWakeSkills > 0 and toWakeSkills or 0)
  end,
}
local zhenshuoL = fk.CreateTriggerSkill{
  name = "#zhenshuoL",
  visible = false,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("@zhenshuoT-turn") ~= 0 end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if table.find(Fk:currentRoom().alive_players, function(p) return p:getMark("@zhenshuoT-turn") ~= 0 end) then
      local targets = table.map(table.filter(room.alive_players, function(p) return p:getMark("@zhenshuoT-turn") ~= 0 end), Util.IdMapper)
      player:broadcastSkillInvoke("YS__zhenshuoturn", 2)
      room:getPlayerById(targets[1]):gainAnExtraTurn(true)
    end
  end,
}
local YS__mengxiang = fk.CreateTriggerSkill{
  name = "YS__mengxiang",
  frequency = Skill.Wake,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player.phase == Player.Start and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player:usedSkillTimes("YS__wuxiang", Player.HistoryGame) > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:handleAddLoseSkills(player, "YS__zhenshuoturn", nil, true, false)
    room:handleAddLoseSkills(player, "-YS__yanshou", nil, true, false)
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("@@YS__yanshou") ~= 0
    end), function(p)
      return p.id
    end)
    for _, targetId in ipairs(availableTargets) do
      room:setPlayerMark(room:getPlayerById(targetId), MarkEnum.UncompulsoryInvalidity, 0)
      room:setPlayerMark(room:getPlayerById(targetId), "@@YS__yanshou", 0)
    end
  end,
}
local YS__eyaogp = fk.CreateTriggerSkill{
  name = "#YS__eyaogp",
  anim_type = "control",
  mute = true,
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForResponse(player, self.name, ".|.|spade,club|hand,equip", "#YS__eyaogp-ask::" .. target.id .. ":" .. data.reason, true)
    if card ~= nil then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__eyao", math.random(1,3))
    player.room:notifySkillInvoked(player, "YS__eyao", "special")
    player.room:retrial(self.cost_data, player, data, self.name, true)
  end,
}
local YS__yanshouJC = fk.CreateTriggerSkill{
  name = "#YS__yanshouJC",
  visible = false,
  frequency = Skill.Compulsory,
  events = {fk.TurnStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local s = 0
    for _, id in ipairs(target:getCardIds("h")) do
      if Fk:getCardById(id).trueName == "shade" then
        s = s + 1
      end
    end
    return target ~= player and not target:isNude() and not target:hasSkill(self) and s ~= 0 and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = {}
    for _, id in ipairs(target:getCardIds("h")) do
      if Fk:getCardById(id).trueName == "shade" then
        table.insert(cards, id)
      end
    end
    room:throwCard(cards, self.name, target, target)
  end,
}

Fk:loadTranslationTable{
  ["YS__ldjj"] = "雷电将军",
  ["YS__eyao"] = "恶曜",
  [":YS__eyao"] = "准备阶段，你可以展示牌堆顶三张牌然后获得其中的黑色牌。出牌阶段开始时，你可以将任意张黑色牌分配给等量角色并令其中所有没有“眼狩”的角色获得“雷罚”标记。<br/>有“雷罚”的角色造成伤害后若目标未死亡，你可以令其进行一次判定，若结果为：红，其摸两张牌；黑，则你对受伤角色造成一点雷电伤害。如此做，其移除“雷罚”并令你获得两张影。<br/>当一名角色的判定牌生效前，你可以打出一张黑色牌替换之。【影】不计入你的手牌上限。",
  ["YS__yanshou"] = "眼狩",
  [":YS__yanshou"] = "锁定技，手牌里有【影】的其他角色所有非锁定技失效，其回合开始时弃置手牌里所有的【影】。当其他角色的【影】因弃置或判定进入弃牌堆后，你可以获得之。",
  ["YS__wuxiang"] = "无想",
  [":YS__wuxiang"] = "限定技，出牌阶段，你可以获得“断绝”直到回合结束。",
  ["YS__duanjue"] = "断绝",
  [":YS__duanjue"] = "出牌阶段限六次，你可以将任意张【影】交给一名其他角色并视为对其使用一张无距离和次数限制的雷【杀】；若你以此法给出的牌大于1，则此【杀】无法响应；不小于3，则此【杀】伤害+1；不小于5，则此【杀】伤害额外+1且额外消耗一次使用次数。",
  ["YS__mengxiang"] = "梦想",
  [":YS__mengxiang"] = "觉醒技，准备阶段，若你已发动〖无想〗，则你获得〖真说〗并失去〖眼狩〗，且修改〖恶曜〗令你在触发“雷罚”后额外获得一张【影】并删去等量角色的描述。",
  ["YS__zhenshuoturn"] = "真说",
  [":YS__zhenshuoturn"] = "当你杀死一名角色后，你可以选择一名角色然后选择一项：1.重置其一个已使用的限定技；2.令其一个未触发的觉醒技视为满足其觉醒条件；3.令其摸三张牌；4.令其于本回合结束后执行一个额外回合（每回合限一次）。",
  ["#ZhenshuoReset"] = "%from 重置了限定技“%arg”",
  ["#leifa_trigger"] = "恶曜",
  ["#YS__eyaogp"] = "恶曜",
  ["#YS__yanshou_judge"] = "眼狩",
  ["#YS__yanshouPrey"] = "眼狩",
  ["#YS__yanshouJC"] = "眼狩",
  ["#YS__duanjue_delay"] = "断绝",
  ["#zhenshouWClear"] = "真说",
  ["#zhenshuoL"] = "真说",
  ["mp"] = "摸牌",
  ["ewhh"] = "额外回合",
  ["xdj"] = "重置限定技",
  ["jsj"] = "触发觉醒技",
  ["@@YS__yanshou"] = "<font color='#5B5B5B'>眼狩</font>",
  ["@@YS__yanshouH-inhand"] = "眼狩",
  ["@YS__duanjue-phase"] = "<font color='#8600FF'>源流</font>",
  ["@@leifa"] = "<font color='#6F00D2'>雷罚</font>",
  ["@zhenshuoW"] = "<font color='#9F35FF'>负愿</font>",
  ["@zhenshuoT-turn"] = "<font color='#D3A4FF'>常道</font>",
  ["#YS__eyaogp-ask"] = "恶曜：你可以打出一张黑色牌替换 %dest 的 “%arg” 判定",
  ["$YS__eyao1"] = "威光无赦！",
  ["$YS__eyao2"] = "无处遁逃！",
  ["$YS__eyao3"] = "泡影看破！",
  ["$YS__yanshou1"] = "…不过须臾之梦。",
  ["$YS__yanshou2"] = "愿望的膨胀，必将带来毁灭。",
  ["$YS__wuxiang1"] = "稻光，亦是永恒！",
  ["$YS__wuxiang2"] = "此刻，寂灭之时！",
  ["$YS__mengxiang1"] = "雷鸣闪电，一瞬即逝。正因如此，才会想要撷取「永恒」。不，才必须掌握「永恒」。",
  ["$YS__mengxiang2"] = "虽然身消梦陨，但是她化作了神樱。这，也是「永恒」。",
  ["$YS__duanjue1"] = "无念，断绝！",
  ["$YS__duanjue2"] = "…肃清阻碍。",
  ["$YS__duanjue3"] = "…诸恶当斩。",
  ["$YS__duanjue4"] = "…枷锁当断。",
  ["$YS__zhenshuoturn1"] = "浮世景色百千年依旧，人之在世却如白露与泡影。虚无。",
  ["$YS__zhenshuoturn2"] = "出征之时已至。",
  ["$YS__ldjj_win_audio"] = "无人相陪，此般花鸟余情，也不过衬托我身不移不变的背景罢了。",
  ["~YS__ldjj"] = "雷鸣，将歇…",
}
YS__eyao:addRelatedSkill(YS__duanjue_delay)
YS__eyao:addRelatedSkill(leifa_trigger)
YS__eyao:addRelatedSkill(YS__eyaogp)
YS__ldjj:addSkill(YS__eyao)
YS__eyao:addRelatedSkill(YS__yanshou_maxcards)
YS__yanshou:addRelatedSkill(YS__yanshou_judge)
YS__yanshou:addRelatedSkill(YS__yanshouPrey)
YS__ldjj:addSkill(YS__yanshou)
YS__ldjj:addRelatedSkill(YS__duanjue)
YS__ldjj:addSkill(YS__wuxiang)
YS__zhenshuoturn:addRelatedSkill(zhenshouWClear)
YS__zhenshuoturn:addRelatedSkill(zhenshuoL)
YS__ldjj:addRelatedSkill(YS__zhenshuoturn)
YS__ldjj:addSkill(YS__mengxiang)
YS__yanshou:addRelatedSkill(YS__yanshouJC)


local YS__wl = General(extension, "YS__wl", "Geo", 4, 4, General.Male)
local YS__wlwin = fk.CreateActiveSkill{ name = "YS__wl_win_audio" }
YS__wlwin.package = extension
Fk:addSkill(YS__wlwin)
local YS__zhengjun = fk.CreateTriggerSkill{
  name = "YS__zhengjun",
  events = {fk.EventPhaseStart, fk.EventPhaseEnd},
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.EventPhaseStart then
        return player:hasSkill(self) and player.phase == Player.Play
      else
        return player.phase == Player.Discard and not player.dead and
        player:usedSkillTimes(self.name, Player.HistoryTurn) > 0 and
        checkZhengsu(player, target, self.name)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name, nil, "整军：你可以进行“整肃”，若成功，则弃牌阶段结束后你可以令一名角色获得“整军”，然后所有有此技能的角色摸两张牌。")
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      startZhengsu(player, player, self.name, "整军：选择你本回合“整肃”的条件")
    else
      local room = player.room
      player:drawCards(1)
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function (p)
        return p.id end), 1, 1, "整军：你可以令一名角色获得此技能", self.name, true)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        if not to:hasSkill("YS__zhengjun") then
        room:handleAddLoseSkills(to, "YS__zhengjun", nil, false, false)
        end
      end
      local availableTargets = table.map(table.filter(room.alive_players, function(p) 
        return p:hasSkill(self)
      end), function(p)
        return p.id
      end)
      for _, targetId in ipairs(availableTargets) do
        local ta = room:getPlayerById(targetId)
        ta:drawCards(1)
      end
      local wl = table.map(table.filter(room.players, function(p) 
        return p:hasSkill(self) and p.general == "YS__wl"
      end), function(p)
        return p.id
      end)
      if wl and not room:getPlayerById(wl[1]).dead then
      room:setPlayerMark(player, "@@zhengjun", 1)
      end
    end
  end,
}
local YS__fangzhen = fk.CreateTriggerSkill{
  name = "YS__fangzhen",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.RoundEnd},
  can_trigger = function(self, event, target, player, data)
    local room = Fk:currentRoom()
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p:hasSkill("YS__zhengjun") and p:getMark("@@zhengjun") ~= 0
    end), function(p)
      return p.id
    end)
    return player:hasSkill(self) and #availableTargets > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p:hasSkill("YS__zhengjun") and p:getMark("@@zhengjun") ~= 0
    end), function(p)
      return p.id
    end)
    if #availableTargets > 1 then
    for _, targetId in ipairs(availableTargets) do
      local ta = room:getPlayerById(targetId)
      if ta:isWounded() then
      room:recover({
        who = ta,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      else
        room:changeShield(ta, 1)
      end
    end
    end
    if #availableTargets > 2 then
      for _, targetId in ipairs(availableTargets) do
        local ta = room:getPlayerById(targetId)
        room:changeShield(ta, 1)
      end
    end
    for _, targetId in ipairs(availableTargets) do
      local ta = room:getPlayerById(targetId)
      room:setPlayerMark(ta, "@@zhengjun", 0)
    end
  end,

  on_lose = function(self, player)
    local room = player.room
    if table.every(room.alive_players, function (p)
      return not p:hasSkill(self, true)
    end) then
      for _, p in ipairs(room.alive_players) do
        if p:hasSkill("YS__zhengjun") then
          room:setPlayerMark(p, "@@zhengjun", 0)
          room:handleAddLoseSkills(p, "-YS__zhengjun", nil, false, false)
        end
      end
    end
  end,
}

YS__wl:addSkill(YS__zhengjun)
YS__wl:addSkill(YS__fangzhen)
Fk:loadTranslationTable{
  ["YS__wl"] = "五郎",
  ["YS__zhengjun"] = "整军",
  ["@@zhengjun"] = "<font color='#EAC100'>整军成功</font>",
  [":YS__zhengjun"] = "出牌阶段开始时，你可以进行“整肃”，弃牌阶段结束后，若“整肃”成功，你摸一张牌且可以令一名角色获得〖整军〗，然后所有有此技能的角色摸一张牌。",
  ["YS__fangzhen"] = "方阵",
  ["#YS__wl_dead"] = "方阵溃散",
  [":YS__fangzhen"] = "每轮结束时，若“整军”成功的人数：大于1，所有整军成功角色回复一点体力(未受伤则改为一点护甲)；大于2，所有整军成功角色获得一点护甲。你死亡时，移除场上所有的〖整军〗。",
}

local YS__jtsl = General(extension, "YS__jtsl", "Electro", 4, 4, General.Female)
local YS__jtslwin = fk.CreateActiveSkill{ name = "YS__jtsl_win_audio" }
YS__jtslwin.package = extension
Fk:addSkill(YS__jtslwin)
local YS__wuyv = fk.CreateTriggerSkill{
  name = "YS__wuyv",
  anim_type = "control",
  events = {fk.CardUseFinished, fk.PreCardUse},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return player:hasSkill(self) and target == player
    elseif event == fk.PreCardUse then
      return target:getMark("@YS__wuyv") > 0 and data.card:getMark("_YS__wuyv") ~= 0 and player:hasSkill(self)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      local to = player.room:askForChoosePlayers(player, table.map(table.filter(player.room.alive_players, function (p)
        return p ~= player and not p:isKongcheng() and p:getMark("@YS__wuyv") ~= p:getHandcardNum() end), function(p)
        return p.id end), 1, 1, "#YS__wuyv-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    elseif event == fk.PreCardUse then
      local mark
      for _, id in ipairs(data.card:isVirtual() and data.card.subcards or {data.card.id}) do
        if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
          if not mark then
            mark = Fk:getCardById(id):getMark("_YS__wuyv")
          elseif mark ~= Fk:getCardById(id):getMark("_YS__wuyv") then
            return false
          end
        else
          return false
        end
      end
      return mark and mark[1] == target.id and mark[2] == player.id
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      local to = room:getPlayerById(self.cost_data)
      local cards = table.filter(to:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("_YS__wuyv") == 0 end)
      local cid = room:askForCardChosen(player, to, {
        card_data = {
          { "YS__wuyv", cards }
        }
      }, self.name)
      room:setCardMark(Fk:getCardById(cid), "_YS__wuyv", {to.id, player.id})
      local num = 0
      for _, id in ipairs(to:getCardIds("he")) do
        if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
          num = num + 1
        end
      end
      room:setPlayerMark(to, "@YS__wuyv", num)
    elseif event == fk.PreCardUse then
      room:doIndicate(player.id, {target.id})
        local choices = {"YS__wuyv_negate", "YS__drawshade2"}
        local choice = room:askForChoice(target, choices, self.name, "#YS__wuyv-choice")
        if choice == "YS__drawshade2" then
          room:moveCards({
            ids = getShade(room, 2),
            to = target.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonPrey,
            proposer = player.id,
            skillName = self.name,
            moveVisible = true,
          })
          for _, id in ipairs(data.card:isVirtual() and data.card.subcards or {data.card.id}) do
            if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
            room:setCardMark(Fk:getCardById(id), "_YS__wuyv", 0)
            end
          end
          local num = 0
          for _, id in ipairs(target:getCardIds("he")) do
            if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
              num = num + 1
            end
          end
          room:setPlayerMark(target, "@YS__wuyv", num)
        elseif choice =="YS__wuyv_negate" then
          if data.toCard ~= nil then
            data.toCard = nil
          else
            data.nullifiedTargets = TargetGroup:getRealTargets(data.tos)
          end
          for _, id in ipairs(data.card:isVirtual() and data.card.subcards or {data.card.id}) do
            if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
            room:setCardMark(Fk:getCardById(id), "_YS__wuyv", 0)
            room:throwCard(id, self.name, target, player)
            end
          end
          local num = 0
          for _, id in ipairs(target:getCardIds("he")) do
            if Fk:getCardById(id):getMark("_YS__wuyv") ~= 0 then
              num = num + 1
            end
          end
          room:setPlayerMark(target, "@YS__wuyv", num)
          player:drawCards(1)
          return true
        end
    end
  end,

  refresh_events = {fk.BeforeCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player:getMark("@YS__wuyv") > 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId):getMark("_YS__wuyv") ~= 0 then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId):getMark("_YS__wuyv") ~= 0 then
            player.room:addPlayerMark(player, "@YS__wuyv", -1)
            player.room:setCardMark(Fk:getCardById(info.cardId), "_YS__wuyv", 0)
          end
        end
      end
    end
  end,

  on_lose = function(self, player)
    local room = player.room
    if table.every(room.alive_players, function (p)
      return not p:hasSkill(self, true)
    end) then
      for _, p in ipairs(room.alive_players) do
        if p:getMark("@YS__wuyv") then
        room:setPlayerMark(p, "@YS__wuyv", 0)
        end
      end
    end
  end,
}
local YS__zhoulei = fk.CreateTriggerSkill{
  name = "YS__zhoulei",
  events = {fk.BeforeCardsMove, fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.BeforeCardsMove then
      if player:hasSkill(self) then
        for _, move in ipairs(data) do
          if move.toArea == Card.Void then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId, true).trueName == "shade" then
                return true
              end
            end
          end
        end
      end
    elseif event == fk.DamageCaused then
      return target == player and data.card and table.contains(data.card.skillNames, "YS__zhoulei")
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.BeforeCardsMove then
      local success, dat = player.room:askForUseActiveSkill(player, "YS__zhoulei_viewas", "#YS__zhoulei-invoke", true)
    if success then
      self.cost_data = dat
      return true
    end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name)
    room:notifySkillInvoked(player, self.name, "offensive")
    if event == fk.BeforeCardsMove then
      local card = Fk.skills["YS__zhoulei_viewas"]:viewAs(self.cost_data.cards)
      local use = {
        from = player.id,
        tos = table.map(self.cost_data.targets, function(id) return {id} end),
        card = card,
        extraUse = true,
      }
      room:useCard(use)
      player:drawCards(1)
    elseif event == fk.DamageCaused then
      local n = 0
      for _, id in ipairs(data.to:getCardIds("h")) do
        if Fk:getCardById(id).trueName == "shade" then
          n = n + 1
        end
      end
      if n > 0 then
        data.damage = data.damage + 1
      end
    end
  end,
}
local YS__zhoulei_viewas = fk.CreateViewAsSkill{
  name = "YS__zhoulei_viewas",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("thunder__slash")
    card:addSubcards(cards)
    card.skillName = "YS__zhoulei"
    return card
  end,
}
local YS__zhoulei_targetmod = fk.CreateTargetModSkill{
  name = "#YS__zhoulei_targetmod",
  anim_type = "offensive",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill("YS__zhoulei") and skill.trueName == "slash_skill" and table.contains(card.skillNames, "YS__zhoulei")
  end
}
Fk:addSkill(YS__zhoulei_viewas)
YS__jtsl:addSkill(YS__wuyv)
YS__jtsl:addSkill(YS__zhoulei)
YS__zhoulei:addRelatedSkill(YS__zhoulei_targetmod)
Fk:loadTranslationTable{
  ["YS__jtsl"] = "九条裟罗",
  ["#YS__wuyv-choose"] = "乌羽：观看一名其他角色的手牌",
  ["#YS__wuyv-choice"] = "乌羽",
  ["YS__drawshade2"] = "获得两张影",
  ["YS__wuyv_negate"] = "令此牌无效",
  ["YS__wuyv"] = "乌羽",
  ["@YS__wuyv"] = "<font color='#B15BFF'>乌羽</font>",
  [":YS__wuyv"] = "当你使用牌结算后：你可以观看一名其他角色的手牌中的非“乌羽”牌，并秘密标记其中一张为“乌羽”；当场上有“乌羽”被使用时，你令使用者选择一项：<br/>1.令此牌无效且你摸一张牌。<br/>2.获得两张【影】",
  ["YS__zhoulei"] = "咒雷",
  ["#YS__zhoulei-invoke"] = "咒雷：将一张黑色牌当无距离限制的雷杀使用。",
  [":YS__zhoulei"] = "当场上有【影】即将进入弃牌堆时，你可以将一张黑色牌当无距离限制的雷杀使用，此杀对手牌里有【影】的角色造成的伤害+1。如此做，你摸一张牌。",
  ["YS__zhoulei_viewas"] = "咒雷",
}

local YS__sjlq = General(extension, "YS__sjlq", "Electro", 6, 6, General.Agender)
local YS__shimo = fk.CreateTriggerSkill{
  name = "YS__shimo",
  anim_type = "defensive",
  events = {fk.HpChanged, fk.Damaged},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
    if event == fk.HpChanged then
      return player:hasSkill(self) and target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player.hp <= math.floor(player.maxHp / 2)
    elseif event == fk.Damaged then
      return player:hasSkill(self) and target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and data.damageType == fk.ThunderDamage
    end 
  end,
  can_wake = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player:drawCards(2)
      room:handleAddLoseSkills(player, "YS__shilei", nil)
      room:addPlayerMark(player, "@YS__shouqunbuff", 1)
    end
  end,
}
local YS__shilei = fk.CreateTriggerSkill{
  name = "YS__shilei",
  anim_type = "offensive",
  events = {fk.DamageCaused, fk.DamageInflicted},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
    data.damageType = fk.ThunderDamage
  end,
  priority = 2,
}
local YS__qinshi = fk.CreateTriggerSkill{
  name = "YS__qinshi",
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card
  end,
  on_cost = function(self, event, target, player, data)
      return true
    end,
  on_use = function(self, event, target, player, data)
    local to = data.to
    if to ~= player then
    player.room:setPlayerMark(to, "@YS__qinshi", 1)
    end
  end,

  refresh_events = {fk.TurnEnd, fk.HpRecover, fk.HpChanged},
  can_refresh = function(self, event, target, player, data)
    return target:getMark("@YS__qinshi") ~= 0 and player:getMark("@YS__qinshi") ~= 0 
  end,
  on_refresh = function(self, event, target, player, data)
  local room = player.room
  if event == fk.TurnEnd then
    if player.hp > 1 then
      room:loseHp(player, 1, self.name)
    end
  elseif event == fk.HpRecover then
    room:setPlayerMark(target, "@YS__qinshi", 0)
  else
    if target.hp == 1 then
      room:setPlayerMark(target, "@YS__qinshi", 0)
    end
  end
end,
}
local YS__shouqun = fk.CreateTriggerSkill{
  name = "YS__shouqun",
  anim_type = "special",
  events = {fk.Death, fk.DrawNCards},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.Death and player:hasSkill(self, false, true) and ((data.damage and data.damage.from == player and target ~= player) or (target == player)) then
      return true
    elseif event == fk.DrawNCards then
      return player:hasSkill(self) and target == player
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Death then
      if target ~= player and data.damage and data.damage.from == player then
      room:addPlayerMark(player, "@YS__shouqunbuff", 1)
      end
      if target == player then
      local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, function (p)
        return p.id end), 1, 1, "兽群：你可以令一名角色获得此技能", self.name, true)
      if #to > 0 then
        to = room:getPlayerById(to[1])
        if not to:hasSkill("YS__shouqun") then
        room:handleAddLoseSkills(to, "YS__shouqun", nil, false, true)
        room:addPlayerMark(to, "@YS__shouqunbuff", player:getMark("@YS__shouqunbuff"))
        end
      end
      end
    elseif event == fk.DrawNCards then
      data.n = data.n + player:getMark("@YS__shouqunbuff")
    end
  end,
}
local YS__shouqunbuff = fk.CreateTargetModSkill {
  name = "#YS__shouqunbuff",
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill"
        and scope == Player.HistoryPhase then
      return player:getMark("@YS__shouqunbuff")
    end
  end,
}
YS__sjlq:addSkill(YS__shimo)
YS__sjlq:addRelatedSkill(YS__shilei)
YS__sjlq:addSkill(YS__qinshi)
YS__sjlq:addSkill(YS__shouqun)
YS__shouqun:addRelatedSkill(YS__shouqunbuff)
Fk:loadTranslationTable{
  ["YS__sjlq"] = "兽境猎犬",
  ["YS__shimo"] = "噬魔",
  [":YS__shimo"] = "觉醒技，当你受到雷电伤害或体力值不大于上限的一半时，你摸两张牌，然后获得〖嗜雷〗和一层“兽境”",
  ["YS__shilei"] = "嗜雷",
  [":YS__shilei"] = "锁定技，你造成或受到的所有伤害视为雷电伤害且伤害+1",
  ["YS__qinshi"] = "侵蚀",
  ["@YS__qinshi"] = "<font color='#3C3C3C'>侵蚀</font>",
  [":YS__qinshi"] = "锁定技，当你用牌造成伤害后，你令其获得“侵蚀”"..
  "<br/><font color='grey'>#\"<b>侵蚀</b>\"：回合结束时，所有“侵蚀”角色流失1点体力，至多流失至1点。当体力值不大于1或回复体力时，移除“侵蚀”。",
  ["YS__shouqun"] = "兽群",
  ["@YS__shouqunbuff"] = "<font color='#921AFF'>兽境</font>",
  [":YS__shouqun"] = "锁定技，当你杀死一名角色后你获得一层“兽境”。<br/>摸牌阶段你额外摸X张牌，你使用【杀】的次数+X。当你死亡时，你可以令一名角色获得此技能并获得X层“兽境”。（X为你的“兽境”层数）",
}

local YS__hlgY = General(extension, "YS__hlgY", "Pyro", 4, 4, General.Male)
local YS__weishen = fk.CreateViewAsSkill{
  name = "YS__weishen",
  mute = true,
  anim_type = "offensive",
  pattern = "analeptic",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("analeptic")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    player:broadcastSkillInvoke(self.name, 2)
    player.room:addPlayerMark(player,"@yanfu", 1)
  end,
  enabled_at_response = function(self, player, cardResponding)
    return not cardResponding
  end
}
local YS__yanfu = fk.CreateTriggerSkill{
  name = "#YS__yanfu",
  anim_type = "offensive",
  events = {fk.DamageCaused, fk.CardUseFinished},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:getMark("@yanfu") ~= 0 and data.card and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("YS__weishen", 1)
    if event == fk.DamageCaused then
    data.damage = data.damage + player:getMark("@yanfu")
    data.damageType = fk.FireDamage
    end
    player.room:setPlayerMark(player, "@yanfu", 0)
  end,
  priority = 2,
}
local YS__jvhe = fk.CreateTriggerSkill{
  name = "YS__jvhe",
  anim_type = "offensive",
  mute = true,
  events = {fk.EventPhaseEnd, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseEnd then
      return target == player and player:hasSkill(self) and
      player.phase == Player.Play and not player:isNude()
    else
      return target == player and player:hasSkill(self) and player.phase == player.Start and player.shield ~= 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local s = player.room:askForSkillInvoke(player, self.name, nil, "是否发动居合")
    if s then
    if event == fk.EventPhaseEnd then 
    local cids = player.room:askForDiscard(player, 0, 2, true, self.name, false, ".", "居合:弃置至多两张牌并获得等量护甲")
      if #cids > 0 then
        self.cost_data = cids
        return true
      end
    else
      return true
    end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, "YS__jvhe")
    if event == fk.EventPhaseEnd then
      player:broadcastSkillInvoke(self.name, 3)
      room:changeShield(player, #self.cost_data)
    else
      local targets = table.filter(room.alive_players, function(p) return player:inMyAttackRange(p) and p ~= player end)
      if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "视为使用一张火杀", self.name, false, false)
      local to = room:getPlayerById(tos[1])
      room:notifySkillInvoked(player, "YS__jvhe")
      player:broadcastSkillInvoke(self.name, math.random(1,2))
      room:changeShield(player, -player.shield)
      room:useVirtualCard("fire__slash", nil, player, to, "YS__jvhe", true)
      end
    end
  end,
}
local YS__kuangluan = fk.CreateTriggerSkill{
  name = "YS__kuangluan",
  anim_type = "offensive",
  events = {fk.Deathed, fk.TurnStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.Deathed then
      return target ~= player and player:hasSkill(self)
    else
      return target == player and player:hasSkill(self) and player:getMark("@@kuangluan") ~= 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Deathed then
      room:setPlayerMark(player,"@@kuangluan", 1)
    else
      room:setPlayerMark(player,"@@kuangluan", 0)
      room:addPlayerMark(player,"@yanfu", 1)
      room:recover{
        who = player,
        num = 2,
        recoverBy = player,
        skillName = self.name,
      }
    end
  end,
}

YS__hlgY:addSkill(YS__weishen)
YS__weishen:addRelatedSkill(YS__yanfu)
YS__hlgY:addSkill(YS__jvhe)
YS__hlgY:addSkill(YS__kuangluan)

Fk:loadTranslationTable{
  ["YS__hlgY"] = "海乱鬼",
  ["YS__weishen"] = "惟神",
  [":YS__weishen"] = "你可以将一张装备牌当【酒】使用，然后你获得一层“炎符”。当你使用【杀】造成伤害时，你令此【杀】伤害+X且视为火焰伤害。你使用【杀】结算后，移除所有“炎符”。（X为你的“炎符”层数）",
  ["#YS__yanfu"] = "炎符",
  ["YS__jvhe"] = "居合",
  [":YS__jvhe"] = "出牌阶段结束时你可以弃置至多两张牌并获得等量护甲。准备阶段，若你有护甲，则你可以失去所有护甲视为使用一张火【杀】。",
  ["YS__kuangluan"] = "狂乱",
  ["@@kuangluan"] = "<font color='#3C3C3C'>狂乱</font>",
  [":YS__kuangluan"] = "锁定技，当场上有其他角色死亡时，你获得“狂乱”。回合开始时，若你有“狂乱”，移除“狂乱”回复2点体力并获得一层“炎符”",
  ["@yanfu"] = "<font color='Red'>炎符</font>",
}

local YS__bcsz = General(extension, "YS__bcsz", "Electro", 4, 4, General.Female)
local YS__bcszwin = fk.CreateActiveSkill{ name = "YS__bcsz_win_audio" }
YS__bcszwin.package = extension
Fk:addSkill(YS__bcszwin)
local YS__yizhou = fk.CreateActiveSkill{
  name = "YS__yizhou",
  anim_type = "control",
  prompt = "#YS__yizhou",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return
      player:usedSkillTimes(self.name, Player.HistoryPhase) < 3 and
      player:hasSkill(self.name) and not player:isNude()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, player, player)
    local nums = target:getMark("@YS__SSY") ~= 0 and string.split(target:getMark("@YS__SSY"), "-") or 0
    local count = target:getMark("@YS__SSY") ~= 0 and tonumber(nums[2]) or 0
    local num = target:getMark("@YS__SSY") == 0 and 1 or tonumber(nums[1]) + 1
    if num > 3 then
      num = 3
    end
    room:setPlayerMark(target, "@YS__SSY", tostring(num) .. "-" .. tostring(count))
  end,
}
local YS__SSY_trigger = fk.CreateTriggerSkill{
  name = "#YS__SSY_trigger",
  anim_type = "control",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    local nums = target:getMark("@YS__SSY") ~= 0 and string.split(target:getMark("@YS__SSY"), "-") or 0
    local trig = nums ~= 0 and 4 - nums[1] or 0
    return
      target == player and
      target:getMark("@YS__SSY") ~= 0 and
      tonumber(nums[2]) >= trig and tonumber(nums[2]) ~= 0
  end,
  on_use = function(self, event, player, target, data)
    local room = player.room
    local nums = target:getMark("@YS__SSY") ~= 0 and string.split(target:getMark("@YS__SSY"), "-") or 0
    local count = target:getMark("@YS__SSY") ~= 0 and tonumber(nums[1]) - 1 or 0
    local countB = 0
    if count < 0 then
      count = 0
    end
    player:broadcastSkillInvoke("YS__yizhou")
    local src = table.find(room.alive_players, function(p) return p:hasSkill("YS__yizhou", true) end)
    room:setPlayerMark(target, "@YS__SSY", tostring(count) .. "-" .. tostring(countB))
    if src then
    room:moveCards({
      to = src.id,
      toArea = Card.PlayerHand,
      ids = room:getSubcardsByRule(data.card, { Card.Processing }),
      proposer = src.id,
      moveReason = fk.ReasonPrey,
    })
    local slash = Fk:cloneCard "thunder__slash"
    slash.skillName = self.name
    room:useCard{
     from = src.id,
     tos = {{target.id}},
     card = slash,
     extraUse = true,
     }
    end
    if count == 0 then
      room:setPlayerMark(target, "@YS__SSY", 0)
    end
  end,

  refresh_events = {fk.PreCardUse, fk.PreCardRespond},
  can_refresh = function(self, event, target, player, data)
    return target == player and target:getMark("@YS__SSY") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local nums = target:getMark("@YS__SSY") ~= 0 and string.split(target:getMark("@YS__SSY"), "-") or 0
    local count = target:getMark("@YS__SSY") ~= 0 and tonumber(nums[2]) + 1 or 0
    room:setPlayerMark(target, "@YS__SSY", nums[1] .. "-" .. tostring(count))
  end,
}
local YS__tianhu = fk.CreateActiveSkill{
  name = "YS__tianhu",
  frequency = Skill.Limited,
  can_use = function (self, player)
    local room = Fk:currentRoom()
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("@YS__SSY") ~= 0
    end), function(p)
      return p.id
    end)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and #availableTargets ~= 0
  end,
  card_filter = Util.FalseFunc,
  card_num = 0,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local availableTargets = table.map(table.filter(room.alive_players, function(p) 
      return p ~= player and p:getMark("@YS__SSY") ~= 0
    end), function(p)
      return p.id
    end)
    if #availableTargets == 0 then return false end
    local num = 0
    if #availableTargets >= 1 then
    for _, targetId in ipairs(availableTargets) do
      local tar = room:getPlayerById(targetId)
      local nums = tar:getMark("@YS__SSY") ~= 0 and string.split(tar:getMark("@YS__SSY"), "-") or 0
      local count = tar:getMark("@YS__SSY") ~= 0 and tonumber(nums[1]) or 0
      local use = {
       from = player.id,
       tos = {{targetId}},
       card = Fk:cloneCard "thunder__slash",
       additionalDamage = count > 1 and 1 or 0,
       extraUse = true,
       }
      use.skillName = "YS__tianhu"
      room:useCard(use)
      if tar.dead then
        player:setSkillUseHistory("YS__tianhu", 0, Player.HistoryGame)
        player:setMark("YS__tianhuT-turn", 1)
      end
      num = num + count
      room:setPlayerMark(room:getPlayerById(targetId), "@YS__SSY", 0)
    end
    player:drawCards(num)
  end
  end,
}
local YS__tianhu_trig = fk.CreateTriggerSkill{
  name = "#YS__tianhu_trig",
  anim_type = "offensive",
  mute = true,
  events = {fk.DamageCaused},
  frequency = Skill.Compulsory,
  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("YS__tianhuT-turn") ~= 0 and player.phase == Player.Finish
  end,
  on_refresh = function(self, event, target, player, data)
    player:gainAnExtraTurn(true)
    player:setMark("YS__tianhuT-turn", 0)
  end,
}
YS__bcsz:addSkill(YS__yizhou)
YS__yizhou:addRelatedSkill(YS__SSY_trigger)
YS__bcsz:addSkill(YS__tianhu)
YS__tianhu:addRelatedSkill(YS__tianhu_trig)
Fk:loadTranslationTable{
  ["YS__bcsz"] = "八重神子",
  ["YS__yizhou"] = "役咒",
  [":YS__yizhou"] = "出牌阶段限三次，你可以弃置一张黑色牌令一名其他角色获得一层“杀生樱”（上限为3）"..
  "<br/><font color='grey'>#\"<b>杀生樱</b>\"：有“杀生樱”的角色每使用或打出X张牌时，你移去其一层“杀生樱”并获得此牌，然后视为对其使用一张雷【杀】。（X为4-杀生樱的层数）",
  ["#YS__yizhou"] = "役咒:令一名角色获得一层“杀生樱”，有概率获得该角色的牌并对其使用雷杀。",
  ["@YS__SSY"] = "<font color='#9F35FF'>杀生樱</font>",
  ["#YS__SSY_trigger"] = "杀生樱",
  ["YS__tianhu"] = "天狐",
  [":YS__tianhu"] = "限定技，出牌阶段你可以移除场上所有“杀生樱”视为对这些角色使用一张雷【杀】，此【杀】对拥有大于一层“杀生樱”的角色造成的伤害+1；然后你摸等同移除“杀生樱”的牌；若你以此法杀死了一名角色，则你重置此技能且结束阶段执行一个额外的回合。",
}

local YS__jqr = General(extension, "YS__jqr", "Electro", 4, 4, General.Female)
local YS__jqrwin = fk.CreateActiveSkill{ name = "YS__jqr_win_audio" }
YS__jqrwin.package = extension
Fk:addSkill(YS__jqrwin)
local YS__qilei = fk.CreateActiveSkill{
  name = "YS__qilei",
  anim_type = "support",
  min_target_num = 1,
  card_num = 0,
  prompt = "#YS__qilei",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards)
    return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):getMark("@@YS__CH") == 0
  end,
  on_use = function(self, room, effect)
  local player = room:getPlayerById(effect.from)
  local target = room:getPlayerById(effect.tos[1])
  room:setPlayerMark(target, "@@YS__CH", 3)
  if player.hp > 1 then
    room:loseHp(player,1)
  end
  end,
}
local YS__CH = fk.CreateTriggerSkill{
  name = "#YS__CH",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and
    player:getMark("@@YS__CH") ~= 0 and
    table.contains({ 3, 6, 9 }, player:getMark("" .. self.name))
  end,
  on_use = function(self, event, player, target, data)
    local room = player.room
    room:addPlayerMark(player, "@@YS__CH", -1)
    if player:isWounded() then
    room:recover({
      who = player,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
    else
      player:drawCards(1,self.name)
    end
    if player:getMark("@@YS__CH") == 0 then
      room:setPlayerMark(player, "" .. self.name, 0)
    end
  end,

  refresh_events = {fk.PreCardUse, fk.PreCardRespond},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@YS__CH") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "" .. self.name, 1)
  end,
}
local YS__fuchu = fk.CreateTriggerSkill{
  name = "YS__fuchu",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return player:hasSkill(self) and not player:isAllNude() and not room.current.dead
    and player:getMark("@YS__fuchutimes") == 0 and target ~= player
  end,
  on_cost = function(self, event, target, player, data)
      return player.room:askForSkillInvoke(player, self.name, nil, "#YS__fuchu-invoke::"..target.id)
    end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@YS__fuchutimes", 2)
    player:throwAllCards("jeh")
    room:damage{
      from = player,
      to = room.current,
      damage = 1,
      damageType = fk.ThunderDamage,
      skillName = self.name,
    }
    room:recover({
      who = player,
      num = 2,
      recoverBy = player,
      skillName = self.name
    })
  end,

  refresh_events = {fk.HpLost},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@YS__fuchutimes") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player,"@YS__fuchutimes", -data.num)
  end,
}
local YS__geshe = fk.CreateTriggerSkill{
  name = "YS__geshe",
  frequency = Skill.Wake,
  events = {fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and
      not player.dead
  end,
  can_wake = function(self, event, target, player, data)
    return not player.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(player, "YS__polong", nil)
  end
}
local YS__polong = fk.CreateTriggerSkill{
  name = "YS__polong",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.PreDamage,fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if event == fk.PreDamage then
      return player:hasSkill(self) and data.from and data.from ~= player and data.to == player
    else
      return player:hasSkill(self) and player:getMark("@@YS__pl-turn") == 0 and target == player
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.PreDamage then
      room:loseHp(data.to, data.damage, self.name)
      return true
    else
      player:broadcastSkillInvoke(self.name)
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
      room:setPlayerMark(player,"@@YS__pl-turn",1)
    end
  end,

  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@YS__pl-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
YS__jqr:addSkill(YS__qilei)
YS__qilei:addRelatedSkill(YS__CH)
YS__jqr:addSkill(YS__fuchu)
YS__jqr:addSkill(YS__geshe)
YS__jqr:addRelatedSkill(YS__polong)
Fk:loadTranslationTable{
  ["YS__jqr"] = "久岐忍",
  ["YS__qilei"] = "祈雷",
  ["#YS__qilei"] = "祈雷：失去体力令一名角色获得增益",
  [":YS__qilei"] = "出牌阶段限一次，你可以失去一点体力（至多流失至1），然后令一名没有“越祓草轮”的角色获得“越祓草轮”"..
  "<br/><font color='grey'>#\"<b>越祓草轮</b>\"：每使用或打出3张牌后，令该角色回复一点体力，若未受伤则摸一张牌，触发3次后移除。",
  ["#YS__CH"] = "越祓草轮",
  ["YS__fuchu"] = "祓除",
  ["#YS__fuchu-invoke"] = "祓除：弃置区域内所有牌，回复体力并对%dest造成一点雷电伤害",
  [":YS__fuchu"] = "昂扬技，其他角色回合结束时，你可以弃置区域内所有牌对其造成一点雷电伤害，然后你回复两点体力。<br/><u>激昂</u>：累计流失2点体力"..
  "<br/><font color='grey'>#\"<b>昂扬技</b>\"：昂扬技发动后，技能失效直到满足<b>激昂</b>条件。",
  ["YS__geshe"] = "割舍",
  [":YS__geshe"] = "觉醒技，当你脱离濒死后，你减一点体力上限，获得〖破笼〗",
  ["YS__polong"] = "破笼",
  [":YS__polong"] = "锁定技，你受到的所有伤害视为体力流失；每回合限一次，当你进入濒死状态后，你回复一点体力，然后本回合你造成的所有伤害+1。",
  ["@@YS__CH"] = "<font color='#9F35FF'>越祓草轮</font>",
  ["@@YS__pl-turn"] = "<font color='#BE77FF'>破笼</font>",
  ["@YS__fuchutimes"] = "祓除",
}
return extension